当使用-static时,如何让gcc/ld遍历许多'-l library'?

Yax*_*Yax 1 c++ linker gcc ld static-linking

我想静态编译pdf2svg所以我将能够在稳定的Debian中使用最新版本.在./configure不给--enable-static选项,所以我在手动添加Makefile -static选项链接.

不幸的是,结果并不像我怀疑的那样.链接给了我很多undefined reference错误.经过一些谷歌搜索,我发现问题是由错误的顺序引起的-lsome_lib.Gcc链接器尝试在每个库中静态链接一次,当它第一次看到它时 - 信息和Stackoverflow问题:为什么链接库的顺序有时会导致GCC错误?.

是否有可能使链接器通过库列表进行多次传递?

Pla*_*aHH 9

也许这就是你搜索的内容(来自gnu ld manpage):

   -( archives -)
   --start-group archives --end-group
       The archives should be a list of archive files.  They may be either explicit file names, or -l options.

       The specified archives are searched repeatedly until no new undefined references are created.  Normally, an archive is searched only once in the order that it is
       specified on the command line.  If a symbol in that archive is needed to resolve an undefined symbol referred to by an object in an archive that appears later on
       the command line, the linker would not be able to resolve that reference.  By grouping the archives, they all be searched repeatedly until all possible references
       are resolved.

       Using this option has a significant performance cost.  It is best to use it only when there are unavoidable circular references between two or more archives.
Run Code Online (Sandbox Code Playgroud)