使用LD链接时候文件的顺序

将多个.o文件链接成可执行文件的时候。如果链接的顺序不对,会产生错误。
《An introduction of gcc》里面有下面一段话:
On Unix-like systems, the traditional behavior of compilers and linkers
is to search for external functions from left to right in the object files
specified on the command line. This means that the object file which
contains the definition of a function should appear after any files which
call that function.

但是也说了:
Most current compilers and linkers will search all object files, regardless
of order, but since not all compilers do this it is best to follow the
convention of ordering object files from left to right.

所以我遇到的问题很有可能就是gcc不支持search all object files.而是从left to right.
以后要注意这一点。

posted @ 2011-09-03 14:44  Jack204  阅读(823)  评论(0编辑  收藏  举报