我编译了一个从另一个项目移植过来的C++项目,编译后链接时有一些 undefined symbol 警告。关键是这些警告太奇怪了。它们分为两种类型:
类型 1:
dld: warning: Undefined symbol **'__record_needed_destruction'** in file './xxx/xx.o'
dld: warning: Undefined symbol **'__memzero'** in file './xxx/xyy.o'
dld: warning: Undefined symbol **'__vec_delete'** in file './xxx/xyz.o'
dld: warning: Undefined symbol **'__vec_new'** in file './xxx/yy/xxx/yyy.o'
dld: warning: Undefined symbol **'__pure_virtual_called'** in file './xxx/zzz.o'
关键是源代码中没有使用这些符号。警告的确切含义是什么?
类型 2:
dld: warning: Undefined symbol in file './xxx/x1.o', './xxx/x2.o', './xxx/x3.o':
nothrow__3std
**std::nothrow**
源码如下:
ApplicationSystem* pApplicationSystem = **new(std::nothrow)** ApplicationSystem{
.....
.....
}
类似的语句出现在3个cpp文件中,std::nothrow的使用有问题吗?
最佳答案
编译器构建目标文件 (.o) 后,链接器需要链接它们并将所有符号名称(例如函数调用)替换为库中的地址。但在您的情况下,他无法解析此地址。
看来你没有在库中提到stdc++。
可能,您需要将项目类型设置为 C++,或者将编译器名称设置为 g++ 而不是 gcc,或者将参数 -lstdc++ 添加到命令行 eclipse 用于构建。
关于c++ - 使用 Eclipse 链接 C++ 项目时出现 undefined symbol 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1558334/