首页 > 其他 > 详细

关于gcc,g++编译选项

时间:2020-01-19 16:13:52      阅读:59      评论:0      收藏:0      [点我收藏+]

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

关于gcc,g++编译选项

原文:https://www.cnblogs.com/alix-1988/p/12213567.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!