Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please explain this linking error: referenced in section .rodata

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
like image 253
shergill Avatar asked Mar 17 '11 01:03

shergill


2 Answers

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.

like image 77
Erik Avatar answered Nov 04 '22 15:11

Erik


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.

like image 3
William Roberts Avatar answered Nov 04 '22 13:11

William Roberts