JeroenD
JeroenD

Reputation: 353

C++ cross compiling from Linux to Windows issue with various libraries

I am trying to cross compile some c++ code from Linux to Windows using MXE/MinGW, but got stuck on some errors:

/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

The following is the bash command I used to compile the code:

$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

I'll try to explain what the command is supposed to do: The first line is the gcc compiler from MinGW, followed by the source files to be compiled. The next lines are supposed to link the MXE include and lib directories for the various libraries. After that are the "-l" flags to include the actual libraries. The libraries that I need are boost, Qt5, fftw, eigen, and hdf5.

I will also include the bash command that I use to compile the code for Linux, which does work correctly:

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

From what I understand from the error messages is that the problem is with the Qt5 and hdf5 libraries not being included correctly (is this indeed the problem?).

I searched on Google for similar problems, and it sounds like the libraries are not included in the correct order. I tried moving the "-lQt*" and "-lhdf5*" flags around, but I keep getting the same error. I also verified that all libraries are installed in MXE, and that the library and header files (.a and .h) of all libraries are present in the included directories.

How can I solve the error messages? Is my understanding of why the errors occur correct?

Upvotes: 0

Views: 656

Answers (0)

Related Questions