Linker 对符号的未定义引用,即使nm指示此符号存在于共享库2中

Linker 对符号的未定义引用,即使nm指示此符号存在于共享库2中,linker,g++,undefined-reference,dynamic-library,Linker,G++,Undefined Reference,Dynamic Library,我在这里找到了同样的答案,但答案对我没有帮助 我正在编写使用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 ma

我在这里找到了同样的答案,但答案对我没有帮助

我正在编写使用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
但例如,当我在libnglib.so中搜索Ng_Init()时,我得到了肯定的结果

$ nm -D libnglib.so | grep Ng_Init
000000000008d0d0 T _ZN5nglib7Ng_InitEv

所以我很困惑为什么会出现未定义的引用错误

demangles to
nglib::Ng_Init()
Ng_Init()
demangles to
nglib::Ng_Init()
Ng_Init()不同