我知道当链接到多个静态库或目标文件时,顺序很重要(依赖库应该在它们的依赖之前列出)。我想知道在使用 ar
创建库文件时是否,同样的规则适用,图书馆内的顺序很重要,或者在同一个 .a
内。文件没有区别。
我正在打包 200 多个具有复杂依赖关系图的目标文件,并且正在做
ar rcs mylib.a objs/*.o
比以正确的顺序列出它们要容易得多。
我正在使用
gcc
,如果它有所作为。
最佳答案
图书馆内的秩序很久以前就很重要。
它在任何更新超过 15-20 年的 UNIX 系统上都不再重要。来自 man ranlib
:
An archive with such an index speeds up linking to the library
and allows routines in the library to call each other without
regard to their placement in the archive.
大多数非古老的 UNIX 系统要么产生
__.SYMDEF
(包含上述索引)在构建存档库时自动生成,或在链接时在内存中构建。
关于gcc - 静态库中目标文件的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8674511/