Dec 2

gcc的参数顺序对链接的影响 不指定

felix021 @ 2010-12-2 13:56 [IT » 软件] 评论(0) , 引用(0) , 阅读(5154) | Via 本站原创 | |
前一阵发现"gcc -static -lm a.c"总是会出现编译错误,后来不得已改成"gcc -static -lm a.c /usr/lib/libm.a",才通过,也算是歪打正着。最近int ijk同学在使用我的woj-land,给我反馈了这个BUG,mark一下,并查到了原始文档,详情如下:

zz from http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

3.13 Options for Linking

......

-llibrary
-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.

The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.

The directories searched include several standard system directories plus any that you specify with -L.

Normally the files found this way are library files—archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with `lib' and `.a' and searches several directories.



欢迎扫码关注:




转载请注明出自 ,如是转载文则注明原出处,谢谢:)
RSS订阅地址: https://www.felix021.com/blog/feed.php
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   *非必须
网址   电邮   [注册]