Please explain this linking error: referenced in section .rodata

痞子三分冷 提交于 2019-11-30 05:30:42

问题


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

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5333871/please-explain-this-linking-error-referenced-in-section-rodata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!