Undefined symbol errors when linking of C++ project using Eclipse

烈酒焚心 提交于 2020-02-02 15:04:20

问题


I compiled one C++ project which transplanted from another project, and there are some undefined symbol warnings while linking after compiled. The point is that these warnings are so strange. They are divided into 2 types:

Type 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'

The key point is that these symbols were not used in the source code. What is exact means of there warings?

Type 2:

dld: warning: Undefined symbol in file './xxx/x1.o', './xxx/x2.o', './xxx/x3.o':
    nothrow__3std
    **std::nothrow**

The source code is below:

ApplicationSystem* pApplicationSystem = **new(std::nothrow)** ApplicationSystem{
.....
.....
}

The similar statements appear in 3 cpp files.Is there something wrong about the use of std::nothrow?


回答1:


After compiler built your object files (.o) linker needs to link them and replace all symbol names (e.g. function calls) with addresses from libraries. But in your case he can't resolve this addresses.

It seems that you haven't mentioned stdc++ among libraries.

Probably, you'll need to set project type as C++, or set compiler name to g++ instead of gcc, or add parameter -lstdc++ to command line eclipse uses for build.



来源:https://stackoverflow.com/questions/1558334/undefined-symbol-errors-when-linking-of-c-project-using-eclipse

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