关于gcc,g++编译选项
gcc中的-Wl,rpath
gcc编译链接动态库时,很有可能编译通过,但是执行时,找不到动态链接库,那是
因为-L选项指定的路径只在编译时有效,编译出来的可执行文件不知道-L选项后面的值,
当然找不到。可以用ldd <your_execute>看看是不有 ‘not found’在你链接的库后面,
解决方法是通过-Wl,rpath=<your_lib_dir>,使得execute记住链接库的位置
gcc -o foo foo.c -L/usr/local/lib -lfoo -Wl,-rpath,/usr/local/lib
gcc -o foo foo.c -L$(prefix)/lib -lfoo -Wl,-rpath=$(prefix)/lib
>> Unfortunately, there are at least three incompatible kinds of >> command-line options that tell the compiler to instruct the linker to >> save library paths in the executable: >> >> -Wl,-rpath,/path/to/dir gcc, g++, FreeBSD, SGI, Sun compilers >> -rpath /path/to/dir Compaq/DEC, SGI compilers >> -Rdir:dir:dir Portland Group, Sun compilers