Cross Compiling with CMake
-
Hi !
I would like to cross compile a Qt application using CMake from Linux to target a Windows platform. I installed successfully the mingw32 compiler on Linux, and I precised in the CMakeLists file to use this compiler instead of the well known g++, by setting the CMake variable CMAKE_CXX_COMPILER to x86_64-w64-mingw32-g++.
Unfortunately, although the cmake $src work fine, the compilation fails totally, by reporting this error :
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1: error adding symbols: File in wrong format
I suppose the link with the Qt libraries doesn't match the expected Qt libraries for Windows build but the Linux ones.
I googled a solution to do this cross compilation but I didn't find anything relevant.
Could anyone please inform me on the way to perform this cross compilation using CMake ?
Thanks a lot !
-
Hi,
The first thing you would have to do is cross-compile Qt with that compiler. Then you can recompile your application using that version of Qt
-
Thanks for your fast answer.
In fact, I tried yesterday to compile Qt with that compiler, using :
./configure -xplatform win32-g++ -device-option CROSS_COMPILE=x86_64-w64-mingw32- (is that correct ?)
but I have the following errors :
Warning: Disabling pkg-config since PKG_CONFIG_LIBDIR is not set.
Warning: Disabling pkg-config since PKG_CONFIG_SYSROOT_DIR is not set.
STL functionality check failed! Cannot build Qt with this STL library.It seems the two first lines are just warnings but the last line is an error.
I suppose I am not setting some variables when configuring Qt, but I have no idea what are the two first variables PKG_CONFIG_LIBDIR and PKG_CONFIG_SYSROOT_DIR.
I tried this :
PKG_CONFIG_LIBDIR=/usr/x86_64-w64-mingw32/lib ./configure -xplatform win32-g++ -device-option CROSS_COMPILE=x86_64-w64-mingw32- -sysroot /usr/x86_64-w64-mingw32
but I still have the same error about the STL.
Thanks a lot for your help !
-
Did you restart configure from a clean state ?
-
Hello !
Indeed, I was trying to compile the dirty sources.
But now I can go to the sudo make install step, and I have the following error :
${somewhere}/qtbase/include/QtCore/../../src/corelib/global/qt_windows.h:63:21:
Here is what I did :
tar -xzf qt-everywhere-opensource-src-5.4.0.tar.gz cd qt-everywhere-opensource-src-5.4.0 PKG_CONFIG_LIBDIR=/usr/x86_64-w64-mingw32/lib ./configure -v -xplatform win32-g++ -device-option CROSS_COMPILE=x86_64-w64-mingw32- -sysroot /usr/x86_64-w64-mingw32 make -j 4 sudo make install
Have I missed something ?
Thanks a lot for your help, it seems I'm close to the joy of cross-compiling, thanks to you !
-
What's the error you are getting ?
-
I haven't see the lack of the error above.
Here is the complete line with the error :
/home/gabriel/qt-everywhere-opensource-src-5.4.0/qtbase/include/QtCore/../../src/corelib/global/qt_windows.h:63:21: fatal error: windows.h: No such file or directory
-
Are you sure you have that header installed on your computer ?
-
Yes, the header windows.h is installed.
dpkg -S windows.h output >> mingw-w64-x86-64-dev: /usr/x86_64-w64-mingw32/include/windows.h dpkg -l mingw-w64-x86-64-dev output >> ii mingw-w64-x86-64-dev (.*) ls -ltr /usr/x86_64-w64-mingw32/include/windows.h ... /usr/x86_64-w64-mingw32/include/windows.h -> ../../share/mingw-w64/include/windows.h
and I precise to the configure script usr/x86_64-w64-mingw32 as sysroot.
Perhaps I missed an option of the configure script ?
Thanks a lot for your help, because I have to go on Windows to compile my Qt application for Windows, unfortunately, and I would like to have not.
-
Try adding (with the space)
-I /usr/x86_64-w64-mingw32/include/
to your configure call.
-
I already tried this, and I had this error :
/usr/x86_64-w64-mingw32/include/malloc.h:209:18: error: expected declaration before end of line
Thanks a lot for your help !