请解释此链接错误:在 .rodata 部分中引用
我正在 32 位 SLES10 机器上进行构建。使用 GCC 3.4.2
这是一个示例错误
`.L8245' referenced in section `.rodata' of CMakeFiles/myproj.dir/c++/util/MyObj.o: defined in discarded section
`.gnu.linkonce.t._ZN5boost9re_detail9reg_grep2INS0_21grep_search_predicateIPKcSaIcEEES4_cNS_12regex_traitsIcEES5_S5_EEjT_T0_SA_RKNS_14reg_expressionIT1_T2_T3_EEjT4_' of CMakeFiles/myproj.dir/c++/util/MyObj.o
I am doing a build on a 32bit SLES10 machine. Using GCC 3.4.2
Here is a sample error
`.L8245' referenced in section `.rodata' of CMakeFiles/myproj.dir/c++/util/MyObj.o: defined in discarded section
`.gnu.linkonce.t._ZN5boost9re_detail9reg_grep2INS0_21grep_search_predicateIPKcSaIcEEES4_cNS_12regex_traitsIcEES5_S5_EEjT_T0_SA_RKNS_14reg_expressionIT1_T2_T3_EEjT4_' of CMakeFiles/myproj.dir/c++/util/MyObj.o
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这通常是由于使用不同的编译器开关编译了 2 个不同的 .cpp,但也使用了相同的模板。生成的模板实例化可能在定义/引用的内容上有所不同,并且如果所选实例化未定义/引用与被丢弃的符号完全相同的符号,则可能会出现此错误。
验证所有 .cpp 均使用完全相同的编译器开关和定义进行编译。如果不可能,请在链接器命令行上重新排序 .obj 文件,特别是尝试将错误消息中提到的 .obj 文件移动到 .obj 文件列表的末尾或开头。
编辑:
此外,如果您要链接预构建的 c++ 库,请查看是否可以复制用于构建这些库的编译器开关。
This is typically due to 2 different .cpp's being compiled with different compiler switches - but also using the same templates. The generated template instantiations may differ in what they define/reference, and if the instantiation that is selected doesn't define/refer to the exact same symbols as the ones that got discarded you may get this error.
Validate that all your .cpp's are compiled with the exact same compiler switches and defines. If this isn't possible, reorder the .obj files on the linker commandline, in particular try to move the .obj files mentioned in the error message to the end or beginning of the .obj file list.
EDIT:
Also, if you're linking against prebuilt c++ libraries, see if you can duplicate the compiler switches used for building these libraries.
这可能是由于使用了较新版本的 binutils。 binutils 版本 2.15 将此视为非致命错误,但 binutils 的更高版本发生了更改,因此链接开始失败。请参阅https://bugzilla.redhat.com/show_bug.cgi?id=191618 类似的报告。
就我而言,我能够通过显式使用 binutils 2.16.1 而不是 binutils 2.17 来再次链接。
This may be due to using a newer version of binutils. binutils version 2.15 treated this as a non-fatal error, but later versions of binutils changed and so the link started failing. See https://bugzilla.redhat.com/show_bug.cgi?id=191618 for a similar report.
In my case, I was able to get things to link once more by explicitly using binutils 2.16.1, instead of binutils 2.17.