0

我正在尝试使用 MXE/MinGW 将一些 c++ 代码从 Linux 交叉编译到 Windows,但遇到了一些错误:

/tmp/ccd6s46b.o:PSTDKernel.cpp:(.text$_ZN9QVector2DixEi[__ZN9QVector2DixEi]+0x29): undefined reference to `_imp___Z9qt_assertPKcS0_i'
/tmp/ccd6s46b.o:PSTDKernel.cpp:(.text$_ZN9QVector3DixEi[__ZN9QVector3DixEi]+0x29): undefined reference to `_imp___Z9qt_assertPKcS0_i'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x12e): undefined reference to `_imp___ZNK6QColor4redFEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x18b): undefined reference to `_imp___ZNK6QColor6greenFEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x1e8): undefined reference to `_imp___ZNK6QColor5blueFEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x245): undefined reference to `_imp___ZNK6QColor6alphaFEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x67c): undefined reference to `_imp___ZNK6QColor3rgbEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x78e): undefined reference to `_imp___ZN6QColoraSERKS_'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x8b6): undefined reference to `_imp___ZNK6QColor4redFEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x8de): undefined reference to `_imp___ZNK6QColor4redFEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x926): undefined reference to `_imp___ZN6QColor7setRedFEd'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x945): undefined reference to `_imp___ZNK6QColor6greenFEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x96d): undefined reference to `_imp___ZNK6QColor6greenFEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x9b5): undefined reference to `_imp___ZN6QColor9setGreenFEd'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x9d4): undefined reference to `_imp___ZNK6QColor5blueFEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0x9fc): undefined reference to `_imp___ZNK6QColor5blueFEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0xa44): undefined reference to `_imp___ZN6QColor8setBlueFEd'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0xa63): undefined reference to `_imp___ZNK6QColor6alphaFEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0xa8b): undefined reference to `_imp___ZNK6QColor6alphaFEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text+0xad3): undefined reference to `_imp___ZN6QColor9setAlphaFEd'
/tmp/ccH81WfL.o:Colors.cpp:(.text$_ZN6QColorC1Ev[__ZN6QColorC1Ev]+0xf): undefined reference to `_imp___ZN6QColor10invalidateEv'
/tmp/ccH81WfL.o:Colors.cpp:(.text$_ZN6QColorC1Eiiii[__ZN6QColorC1Eiiii]+0x2a): undefined reference to `_imp___ZN6QColor6setRgbEiiii'
/tmp/cc1pzPQK.o:Image.cpp:(.text+0x1210): undefined reference to `_imp___ZN6QImage8setPixelEiij'
/tmp/cc1pzPQK.o:Image.cpp:(.text+0x1593): undefined reference to `_imp___ZN6QImage8setColorEij'
/tmp/cc1pzPQK.o:Image.cpp:(.text+0x1804): undefined reference to `_imp___ZNK6QImage4saveERK7QStringPKci'
/tmp/cc1pzPQK.o:Image.cpp:(.text+0x18b9): undefined reference to `_imp___ZNK6QImage4saveERK7QStringPKci'
/tmp/cc1pzPQK.o:Image.cpp:(.text+0x1968): undefined reference to `_imp___ZNK6QImage4saveERK7QStringPKci'
/tmp/cc1pzPQK.o:Image.cpp:(.text+0x23a5): undefined reference to `_imp___ZN6QImage8setColorEij'
/tmp/cc1pzPQK.o:Image.cpp:(.text+0x2400): undefined reference to `_imp___ZNK6QColor3rgbEv'
/tmp/cc1pzPQK.o:Image.cpp:(.text+0x242d): undefined reference to `_imp___ZN6QImage8setColorEij'
/tmp/cc1pzPQK.o:Image.cpp:(.text+0x2481): undefined reference to `_imp___ZN6QImage8setPixelEiij'
/tmp/cc1pzPQK.o:Image.cpp:(.text+0x272b): undefined reference to `_imp___ZNK6QImage4saveERK7QStringPKci'
/tmp/cc1pzPQK.o:Image.cpp:(.text+0x27ec): undefined reference to `_imp___ZNK6QImage4saveERK7QStringPKci'
/tmp/cc1pzPQK.o:Image.cpp:(.text+0x28a1): undefined reference to `_imp___ZNK6QImage4saveERK7QStringPKci'
/tmp/cc1pzPQK.o:Image.cpp:(.text$_ZN7QString8fromUtf8EPKci[__ZN7QString8fromUtf8EPKci]+0x34): undefined reference to `_imp___ZN7QString15fromUtf8_helperEPKci'
/tmp/cc1pzPQK.o:Image.cpp:(.text$_ZN15QTypedArrayDataItE10deallocateEP10QArrayData[__ZN15QTypedArrayDataItE10deallocateEP10QArrayData]+0x1d): undefined reference to `_imp___ZN10QArrayData10deallocateEPS_jj'
/tmp/cc1pzPQK.o:Image.cpp:(.text$_ZN9__gnu_cxx13new_allocatorI6QImageE9constructIS1_JRiS4_NS1_6FormatEEEEvPT_DpOT0_[__ZN9__gnu_cxx13new_allocatorI6QImageE9constructIS1_JRiS4_NS1_6FormatEEEEvPT_DpOT0_]+0x9d): undefined reference to `_imp___ZN6QImageC1EiiNS_6FormatE'
/home/jeroen/openPSTD/openPSTD-version_backend/mxe-new/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.5.0/../../../../i686-w64-mingw32.static/lib/../lib/libhdf5.a(H5Zdeflate.o):H5Zdeflate.c:(.text+0x157): undefined reference to `inflateInit_'
/home/jeroen/openPSTD/openPSTD-version_backend/mxe-new/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.5.0/../../../../i686-w64-mingw32.static/lib/../lib/libhdf5.a(H5Zdeflate.o):H5Zdeflate.c:(.text+0x1ca): undefined reference to `inflate'
/home/jeroen/openPSTD/openPSTD-version_backend/mxe-new/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.5.0/../../../../i686-w64-mingw32.static/lib/../lib/libhdf5.a(H5Zdeflate.o):H5Zdeflate.c:(.text+0x1e8): undefined reference to `inflateEnd'
/home/jeroen/openPSTD/openPSTD-version_backend/mxe-new/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.5.0/../../../../i686-w64-mingw32.static/lib/../lib/libhdf5.a(H5Zdeflate.o):H5Zdeflate.c:(.text+0x278): undefined reference to `inflateEnd'
/home/jeroen/openPSTD/openPSTD-version_backend/mxe-new/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.5.0/../../../../i686-w64-mingw32.static/lib/../lib/libhdf5.a(H5Zdeflate.o):H5Zdeflate.c:(.text+0x335): undefined reference to `inflateEnd'
/home/jeroen/openPSTD/openPSTD-version_backend/mxe-new/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.5.0/../../../../i686-w64-mingw32.static/lib/../lib/libhdf5.a(H5Zdeflate.o):H5Zdeflate.c:(.text+0x45c): undefined reference to `compress2'
/home/jeroen/openPSTD/openPSTD-version_backend/mxe-new/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.5.0/../../../../i686-w64-mingw32.static/lib/../lib/libboost_serialization-mt.a(extended_type_info_typeid.o):extended_type_info_typeid.cpp:(.text+0x116): undefined reference to `std::type_info::before(std::type_info const&) const'
/home/jeroen/openPSTD/openPSTD-version_backend/mxe-new/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.5.0/../../../../i686-w64-mingw32.static/lib/../lib/libboost_serialization-mt.a(extended_type_info_typeid.o):extended_type_info_typeid.cpp:(.text+0x159): undefined reference to `std::type_info::before(std::type_info const&) const'
/home/jeroen/openPSTD/openPSTD-version_backend/mxe-new/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.5.0/../../../../i686-w64-mingw32.static/lib/../lib/libboost_serialization-mt.a(extended_type_info_typeid.o):extended_type_info_typeid.cpp:(.text+0x2c4): undefined reference to `std::type_info::before(std::type_info const&) const'
/home/jeroen/openPSTD/openPSTD-version_backend/mxe-new/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.5.0/../../../../i686-w64-mingw32.static/lib/../lib/libboost_serialization-mt.a(extended_type_info_typeid.o):extended_type_info_typeid.cpp:(.text+0x316): undefined reference to `std::type_info::before(std::type_info const&) const'
/home/jeroen/openPSTD/openPSTD-version_backend/mxe-new/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.5.0/../../../../i686-w64-mingw32.static/lib/../lib/libboost_serialization-mt.a(extended_type_info_typeid.o):extended_type_info_typeid.cpp:(.text+0x4b9): undefined reference to `std::type_info::before(std::type_info const&) const'
/home/jeroen/openPSTD/openPSTD-version_backend/mxe-new/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.5.0/../../../../i686-w64-mingw32.static/lib/../lib/libboost_serialization-mt.a(extended_type_info_typeid.o):extended_type_info_typeid.cpp:(.text+0x500): more undefined references to `std::type_info::before(std::type_info const&) const' follow
collect2: error: ld returned 1 exit status

以下是我用来编译代码的 bash 命令:

$mxe/usr/bin/i686-w64-mingw32.static-gcc \
../CLI/*.cpp ../kernel/*.cpp ../kernel/core/*.cpp \
../shared/*.cpp ../shared/export/*.cpp ../unqlite/*.c \
-o OpenPSTD-cli.exe \
-I$mxe/usr/i686-w64-mingw32.static/include \
-L$mxe/usr/i686-w64-mingw32.static/include \
-I$mxe/usr/i686-w64-mingw32.static/qt5/include \
-I$mxe/usr/i686-w64-mingw32.static/qt5/lib \
-L$mxe/usr/i686-w64-mingw32.static/qt5/lib \
-I$mxe/usr/i686-w64-mingw32.static/include/eigen3 \
-I$mxe/usr/i686-w64-mingw32.static/qt5/include/QtCore \
-I$mxe/usr/i686-w64-mingw32.static/qt5/include/QtTest \
-I$mxe/usr/i686-w64-mingw32.static/qt5/include/QtGui \
-L$mxe/usr/i686-w64-mingw32.static/qt5/include/QtCore \
-L$mxe/usr/i686-w64-mingw32.static/qt5/include/QtGui \
-lstdc++ -pthread -lfftw3f \
-lhdf5_hl -lhdf5 -lQt5Core -lQt5Test -lQt5Gui -fPIC -lm \
-lboost_unit_test_framework-mt -lboost_chrono-mt -lboost_system-mt -lboost_timer-mt \
-lboost_regex-mt -lboost_iostreams-mt -lboost_serialization-mt -lboost_filesystem-mt \
-lboost_thread_win32-mt -lboost_date_time-mt -lboost_atomic-mt -lboost_program_options-mt \
-DQT_NO_VERSION_TAGGING -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED \
-std=c++11

我将尝试解释该命令应该做什么:第一行是来自 MinGW 的 gcc 编译器,然后是要编译的源文件。下一行应该链接各种库的 MXE 包含和 lib 目录。之后是包含实际库的“-l”标志。我需要的库是 boost、Qt5、fftw、eigen 和 hdf5。

我还将包含用于编译 Linux 代码的 bash 命令,该命令可以正常工作:

gcc ../CLI/*.cpp ../kernel/*.cpp ../kernel/core/*.cpp \
../shared/*.cpp ../shared/export/*.cpp ../unqlite/*.c \
-o OpenPSTD-cli -lstdc++ -pthread -lfftw3f -lhdf5 -lhdf5_hl \
-I/usr/include/eigen3 -I$HOME/Qt/5.9.1/gcc_64/include \
-I$HOME/Qt/5.9.1/gcc_64/include/QtCore -I$HOME/Qt/5.9.1/gcc_64/include/QtTest \
-I$HOME/Qt/5.9.1/gcc_64/include/QtGui \
-L$HOME/Qt/5.9.1/gcc_64/include/QtCore -L$HOME/Qt/5.9.1/gcc_64/include/QtGui \
-lQt5Core -lQt5Test -lQt5Gui -fPIC -lm \
-lboost_unit_test_framework -lboost_chrono -lboost_system -lboost_timer \
-lboost_regex -lboost_iostreams -lboost_serialization -lboost_filesystem \
-lboost_thread -lboost_date_time -lboost_atomic -lboost_program_options \
-DQT_NO_VERSION_TAGGING -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED

根据我从错误消息中了解到的情况,问题在于没有正确包含 Qt5 和 hdf5 库(这确实是问题吗?)。

我在 Google 上搜索了类似的问题,听起来这些库的顺序不正确。我尝试移动“-lQt*”和“-lhdf5*”标志,但我一直收到同样的错误。我还验证了所有库都安装在 MXE 中,并且所有库的库和头文件(.a 和 .h)都存在于包含的目录中。

如何解决错误消息?我对错误发生原因的理解是否正确?

4

0 回答 0