【问题标题】:order of object files in static library静态库中目标文件的顺序
【发布时间】:2011-12-29 23:03:50
【问题描述】:

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

ar rcs mylib.a objs/*.o

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

我正在使用gcc,如果它有所作为的话。

【问题讨论】:

    标签: gcc static-libraries static-linking unix-ar


    【解决方案1】:

    库中的顺序使用很久以前就很重要了。

    在任何 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(包含上述索引),要么在链接时在内存中构建它。

    【讨论】:

    • “库中的顺序在很久以前就很重要......” - 由于 C++ 静态对象初始化顺序,这不一定正确。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    • 2011-06-21
    • 1970-01-01
    • 2011-02-06
    • 2014-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多