I try to work on shared library.
In detail, I following this link: http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html.
Everything ok with this command:
$ gcc -L/home/user/foo -Wl,-rpath=/home/user/foo -Wall -o test main.c -lfoo
$ ./test
But when i change from gcc to /usr/bin/c++, ANd change commands to:
$ /usr/bin/c++ -L/home/user/foo -Wl,-rpath=/home/user/foo -Wall -o test2 main.c -lfoo
/tmp/ccpEHbNV.o: In function `main':
main.c:(.text+0x16): undefined reference to `foo()'
collect2: error: ld returned 1 exit status
It can't find the method foo in my libfoo.so.
I also try by another way with -rdynamic, It also work well with gcc:
gcc -rdynamic ./libfoo.so -Wl,-rpath=/home/user/foo -Wall -o test main.c -lfoo
But It also have the same error with /usr/bin/c++.
Please show me how to make it work with /usr/bin/c++.
Thank a lot.
main.cwith eithergcc, org++, not both. You could also wrap the declarations withextern "C"and appropriate compiler guards if you really do need to use the lib in both C and C++./usr/bin/c++is a standard name for C++ compiler. It can be any compiler on your system. For example, on my system it is the same asg++. You can check it withls -l /usr/bin/{g,c}++. On some systemsc++is a symlink tog++. On my system it is just a copy of g++ (checked withmd5sum /usr/bin/{g,c}++). So it is impossible to answer unless you tell us which compiler is disguised under/usr/bin/c++. By the way, the commands work withg++, so it is unlikely that yourc++isg++.