linker error cannot find symbol name in library

2019-07-24 18:02发布

问题:

g++ (GCC) 4.7.2 
3.7.6-201.fc18.x86_64 #1 SMP Mon Feb 4 15:54:08 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Fedora release 18 (Spherical Cow)

Hello,

I am compiling and having a problem trying to link a program.

The linker error is:

/usr/bin/ld: point.o: undefined reference to symbol '_Znwj@@GLIBCXX_3.4'
/usr/bin/ld: note: '_Znwj@@GLIBCXX_3.4' is defined in DSO /lib/libstdc++.so.6 so try adding it to the linker command line
/lib/libstdc++.so.6: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status

This object file is point.o is trying to call a function that doesn't exist in libstdc++.

When I try and check if the symbol name does exist using readelf I can't find it.

readelf --all libstdc++.so.6.0.17 | grep _Znwj@@GLIBCXX_3.4

Is this because the point.o is looking for a symbol in a older libstdc++ that could have been removed in a later version?

Many thanks for any suggestions,

回答1:

In my case I was using gcc not g++. It used to work in '12, but a later build on a different machine in '14 choked. The gnu compiler has indeed changed. The answer in my case was to add

  -lstdc++

onto the end of the linking line, as the error messages suggest. HTH.



标签: linker g++