链接器错误无法在库中找到符号名称

时间:2013-02-15 05:11:58

标签: linker g++

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)

您好,

我正在编译并在尝试链接程序时遇到问题。

链接器错误是:

/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

此目标文件point.o正在尝试调用libstdc ++中不存在的函数。

当我尝试使用readelf检查符号名称是否存在时,我找不到它。

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

这是因为point.o正在寻找旧版libstdc ++中的符号,该符号可能在以后的版本中删除了吗?

非常感谢任何建议,

1 个答案:

答案 0 :(得分:9)

在我的情况下,我使用gcc而不是g ++。它曾经在 12中工作,但后来在不同的机器上构建了#14; gnu编译器确实发生了变化。我的答案是添加

  -lstdc++

到链接行的末尾,如错误消息所示。 HTH。