首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

gcc编译依托

2012-09-01 
gcc编译依赖gcc编译的时候,依赖库是有顺序的,越基础的库越要写在后面,因为它有可能出现这样的情况,B依赖于

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 "-)"

热点排行