首页 > 解决方案 > g++:未定义引用`_imp___ZN5pluma13Plxxxx

问题描述

我想编译项目“pluma”。我使用mingw,并使用默认cbp的代码块打开这个项目。前两个项目进展顺利,日志如下:

mingw32-g++.exe -std=c++0x -Wall -DPLUMA_EXPORTS -g -O0 -I..\..\include -I..\..\src -c F:\workspace\mec\Pluma-1.1\src\Pluma\Dir.cpp -o ..\..\ztemp\mingw\debug\src\Pluma\Dir.o
mingw32-g++.exe -std=c++0x -Wall -DPLUMA_EXPORTS -g -O0 -I..\..\include -I..\..\src -c F:\workspace\mec\Pluma-1.1\src\Pluma\DLibrary.cpp -o ..\..\ztemp\mingw\debug\src\Pluma\DLibrary.o
mingw32-g++.exe -std=c++0x -Wall -DPLUMA_EXPORTS -g -O0 -I..\..\include -I..\..\src -c F:\workspace\mec\Pluma-1.1\src\Pluma\Host.cpp -o ..\..\ztemp\mingw\debug\src\Pluma\Host.o
mingw32-g++.exe -std=c++0x -Wall -DPLUMA_EXPORTS -g -O0 -I..\..\include -I..\..\src -c F:\workspace\mec\Pluma-1.1\src\Pluma\PluginManager.cpp -o ..\..\ztemp\mingw\debug\src\Pluma\PluginManager.o
mingw32-g++.exe -std=c++0x -Wall -DPLUMA_EXPORTS -g -O0 -I..\..\include -I..\..\src -c F:\workspace\mec\Pluma-1.1\src\Pluma\Provider.cpp -o ..\..\ztemp\mingw\debug\src\Pluma\Provider.o
mingw32-g++.exe -shared  -Wl,--out-implib=..\..\lib\libpluma-d.a -Wl,--dll  ..\..\ztemp\mingw\debug\src\Pluma\Dir.o ..\..\ztemp\mingw\debug\src\Pluma\DLibrary.o ..\..\ztemp\mingw\debug\src\Pluma\Host.o ..\..\ztemp\mingw\debug\src\Pluma\PluginManager.o ..\..\ztemp\mingw\debug\src\Pluma\Provider.o  -o ..\..\lib\pluma-d.dll  
Output file is ..\..\lib\pluma-d.dll with size 1.36 MB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))

mingw32-g++.exe -Wall -DPLUGIN_EXPORTS -g -O0 -I..\..\..\include -I..\..\src\interface -I..\..\src\plugin -c F:\workspace\mec\Pluma-1.1\example\src\interface\Warrior.cpp -o ..\..\..\ztemp\mingw\elite-warriors\debug\src\interface\Warrior.o
mingw32-g++.exe -Wall -DPLUGIN_EXPORTS -g -O0 -I..\..\..\include -I..\..\src\interface -I..\..\src\plugin -c F:\workspace\mec\Pluma-1.1\example\src\plugin\Connector.cpp -o ..\..\..\ztemp\mingw\elite-warriors\debug\src\plugin\Connector.o
mingw32-g++.exe -shared   -Wl,--dll -L..\..\..\lib ..\..\..\ztemp\mingw\elite-warriors\debug\src\interface\Warrior.o ..\..\..\ztemp\mingw\elite-warriors\debug\src\plugin\Connector.o  -o ..\..\bin\plugins\elite-warriors-d.dll -lpluma-d  
Output file is ..\..\bin\plugins\elite-warriors-d.dll with size 269.04 KB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))

但是当我编译第三个项目并与之前生成的库链接时。我得到以下日志:

mingw32-g++.exe -Wall -g -O0 -I..\..\..\include -I..\..\src\interface -I..\..\src\host -c F:\workspace\mec\Pluma-1.1\example\src\host\Main.cpp -o ..\..\..\ztemp\mingw\aztec-warfare\debug\src\host\Main.o
mingw32-g++.exe -Wall -g -O0 -I..\..\..\include -I..\..\src\interface -I..\..\src\host -c F:\workspace\mec\Pluma-1.1\example\src\interface\Warrior.cpp -o ..\..\..\ztemp\mingw\aztec-warfare\debug\src\interface\Warrior.o
mingw32-g++.exe -L..\..\..\lib -L..\..\..\lib -o ..\..\bin\aztecs-d.exe ..\..\..\ztemp\mingw\aztec-warfare\debug\src\host\Main.o ..\..\..\ztemp\mingw\aztec-warfare\debug\src\interface\Warrior.o  -lpluma-d  
F:\workspace\mec\Pluma-1.1\example\src\host\Main.cpp: In function 'int main()':
F:\workspace\mec\Pluma-1.1\example\src\host\Main.cpp:30:16: warning: deleting object of abstract class type 'Warrior' which has non-virtual destructor will cause undefined behavior [-Wdelete-non-virtual-dtor]
   30 |         delete warrior;
      |                ^~~~~~~
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: ..\..\..\ztemp\mingw\aztec-warfare\debug\src\host\Main.o: in function `main':
F:/workspace/mec/Pluma-1.1/example/src/host/Main.cpp:15: undefined reference to `_imp___ZN5pluma13PluginManager14loadFromFolderERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb'
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: ..\..\..\ztemp\mingw\aztec-warfare\debug\src\host\Main.o: in function `ZN5pluma5Pluma18acceptProviderTypeI15WarriorProviderEEvv':
F:\workspace\mec\Pluma-1.1\example\build\mingw/../../../include/Pluma/Pluma.inl:35: undefined reference to `_imp___ZN5pluma13PluginManager12registerTypeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjj'
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: ..\..\..\ztemp\mingw\aztec-warfare\debug\src\host\Main.o: in function `ZN5pluma5Pluma12getProvidersI15WarriorProviderEEvRSt6vectorIPT_SaIS5_EE':
F:\workspace\mec\Pluma-1.1\example\build\mingw/../../../include/Pluma/Pluma.inl:46: undefined reference to `_imp___ZNK5pluma13PluginManager12getProvidersERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
collect2.exe: error: ld returned 1 exit status

但是,我使用“nm libpluma-da”查看符号,我看到:

00000000 I __imp___ZN5pluma13PluginManager14loadFromFolderERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb
00000000 I __imp___ZN5pluma13PluginManager12registerTypeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjj
00000000 I __imp___ZNK5pluma13PluginManager12getProvidersERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

这些符号是存在的,但只有它们以“__imp”为前缀。前缀中还有一个“_”。这是问题吗?我该如何解决?

标签: c++cwindowsc++11gcc

解决方案


我知道出了什么问题。在 lib 目录中,还有其他名为“libpluma.dll.a, libpluma-d.dll.a,pluma.dll”的库,它是附加在项目中的。可能 mingw-g++ 使用 libpluma-d.dll.a,导致链接器出错。当我删除这些库时,我成功了。


推荐阅读