gcc编译依赖

gcc编译的时候,依赖库是有顺序的,越基础的库越要写在后面,因为它有可能出现这样的情况,B依赖于C同时A依赖于C,如果这样写gcc -o E B C A,则有可能造成C中的某些函数找不到在B中的实现,其原因可以在gcc的帮助里找到:
-l library
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)
It makes a difference where in the command you write this option;the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.

就是指B依赖于C,B中使用的函数在C中找到之后,C中定义的其他的函数不被加载,所以此时链接A的时候,A中的某些依赖于C的函数就找不到了,因为没有加载的这些函数,正确的编译语句应该写成gcc A -o E B C.
如果不想繁琐地调整这些依赖顺序,那可以使用-Xlinker参数:
gcc -o E -Xlinker "-(" B C A -Xlink "-)"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值