静态库中目标文件的顺序

Bar*_*uch 4 gcc static-libraries unix-ar static-linking

我知道当链接到多个静态库或目标文件时,顺序很重要(依赖库应该在它们的依赖项之前列出).我想知道,在创建库文件时ar,是否应用此相同规则并且库中的顺序很重要,或者在同一.a文件中它是否有所作为.
我正在打包200多个带有复杂依赖关系图的目标文件,并且这样做

ar rcs mylib.a objs/*.o
Run Code Online (Sandbox Code Playgroud)

然后以正确的顺序列出它们要容易得多.

我正在使用gcc,如果它有所作为.

Emp*_*ian 6

库中的顺序使用于前事很长一段时间.

它在任何比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.
Run Code Online (Sandbox Code Playgroud)

大多数非古老的UNIX系统__.SYMDEF在构建存档库时自动生成(包含上面的索引),或者在链接时在内存中构建它.