【问题标题】:g++: undefined reference to `_imp___ZN5pluma13Plxxxxg++:未定义引用`_imp___ZN5pluma13Plxxxx
【发布时间】:2020-08-13 01:26:07
【问题描述】:

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

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-d.a”来检查符号,我看到了:

00000000 I __imp___ZN5pluma13PluginManager14loadFromFolderERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb
00000000 I __imp___ZN5pluma13PluginManager12registerTypeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjj
00000000 I __imp___ZNK5pluma13PluginManager12getProvidersERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

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

【问题讨论】:

  • 您需要对所有这些都使用相同的标准修订版(最好也是所有相同的编译器标志),关于缺少字符串函数的消息是因为 C++11 之前的字符串与 C+ 不同您在第一部分而不是第二部分中请求的 +11 字符串

标签: c++ c windows c++11 gcc


【解决方案1】:

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

【讨论】:

  • 这只是随机尝试,直到某些东西看起来有效。解决方案需要描述核心问题。这需要作者理解问题。
猜你喜欢
  • 2016-07-21
  • 2014-08-05
  • 2010-09-23
  • 2011-10-22
  • 1970-01-01
  • 1970-01-01
  • 2020-01-29
  • 2013-02-03
相关资源
最近更新 更多