`
javaFlood
  • 浏览: 10202 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

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 "-)"
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics