强制忽略重复的符号

Force ignore duplicate symbols?

本文关键字:符号      更新时间:2023-10-16

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

ld: warning: option -m is obsolete and being ignored
ld: duplicate symbol <function name>

是否有办法强制通过构建。从我所看到的"复制"函数是相同的,只是构建过程失控了。这个项目真的很大(还有一堆遗留的c和c++代码),我真的想避免花几个小时调查构建过程。是否有"快速解决方案"?我真的只需要运行这个程序一次,所以我可以忍受(一些)稳定性问题。

来自GNU ld手册页:

       --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.

在我的系统上搜索man ld(查找"duplicate"),显示如下:

   --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.

试试。也许它能解决你的问题。