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
原文链接: https://www.cnblogs.com/alix-1988/p/12213567.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;
也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/401057
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!