强制忽略重复符号?

Kru*_*lur 8 c c++ macos ld

我正在使用静态库的项目构建一些遗留代码.现在,我收到很多这样的错误:

ld: warning: option -m is obsolete and being ignored
ld: duplicate symbol <function name>
Run Code Online (Sandbox Code Playgroud)

有没有办法强制通过构建.从我所看到的"重复"功能是相同的,它只是构建过程已经失控.该项目非常庞大(以及一系列遗留的c和c ++代码),我真的希望避免花费数小时来调查构建过程.有"快速修复"吗?我真的只需要运行一次这个程序,所以我可以忍受(某些)稳定性问题.

Tho*_*ard 6

来自 GNUld手册页:

       --allow-multiple-definition
       -z muldefs
           Normally when a symbol is defined multiple times, the linker will
           report a fatal error. These options allow multiple definitions and
           the first definition will be used.
Run Code Online (Sandbox Code Playgroud)

  • 我认为当且仅当重复的符号定义相同时这是“安全的”?最好有一个更仔细的“--allow-identical-definitions”,如果存在多个不同的定义,这仍然是致命的 (2认同)

pmg*_*pmg 1

在我的系统上搜索man ld(“重复”),出现了这个:

   --traditional-format
       For some targets, the output of ld is different in some ways from
       the output of some existing linker.  This switch requests ld to use
       the traditional format instead.

       For example, on SunOS, ld combines duplicate entries in the symbol
       string table.  This can reduce the size of an output file with full
       debugging information by over 30 percent.  Unfortunately, the SunOS
       "dbx" program can not read the resulting program ("gdb" has no
       trouble).  The --traditional-format switch tells ld to not combine
       duplicate entries.
Run Code Online (Sandbox Code Playgroud)

尝试一下。也许它可以解决你的问题。