我在这里发现了同样的问题,但答案对我没有帮助。
我正在编写使用nglib库的测试应用程序。但是当我试图编译它时,我得到了未定义的引用:
$ g++ test1.cpp -L. -lnglib
test1.cpp: In function ‘int main()’:
/tmp/cchcKZfx.o:test1.cpp:function main: error: undefined reference to 'Ng_Init()'
/tmp/cchcKZfx.o:test1.cpp:function main: error: undefined reference to 'Ng_NewMesh()'
...
/tmp/cchcKZfx.o:test1.cpp:function main: error: undefined reference to 'Ng_Exit()'
collect2: ld returned 1 exit status
,但例如,当我搜索Ng_Init()在libnglib。所以,我得到了肯定的结果。
$ nm -D libnglib.so | grep Ng_Init
000000000008d0d0 T _ZN5nglib7Ng_InitEv
所以我很困惑为什么我得到未定义的引用错误?!
_ZN5nglib7Ng_InitEv
转到nglib::Ng_Init()
,与Ng_Init()
不同