Qt6 cross compile for Windows
-
Hi,
I'm trying to cross-compile Qt 6.2.1. Target - Windows, my machine OS - Linux (Mint 20.2) (both 64bit). Unfortunately I can't compile it on Windows.
My configure cmd:
./../qt-everywhere-src-6.2.1/configure -prefix $PWD/. -platform linux-gcc-64 -xplatform win32-g++ -device-option CROSS_COMPILE=/usr/bin/x86_64-w64-mingw32- -opensource -opengl desktop -qt-host-path /home/papoj/Projects/host_qtbuild
At the end of CMake work I'm getting this:
CMake Warning: Manually-specified variables were not used by the project: QT_QMAKE_DEVICE_OPTIONS
And then, after cmake --build . --parallel:
FAILED: qtbase/src/tools/bootstrap/CMakeFiles/Bootstrap.dir/__/__/corelib/global/qglobal.cpp.o /usr/bin/c++ -DHAVE_CONFIG_H -DQT_BOOTSTRAPPED -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_DEBUG -DQT_NO_FOREACH -DQT_USE_QSTRINGBUILDER -DQT_VERSION_MAJOR=6 -DQT_VERSION_MINOR=2 -DQT_VERSION_PATCH=1 -DQT_VERSION_STR=\"6.2.1\" -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I/home/papoj/Projects/qtbuild/qtbase/src/corelib/Core_autogen/include -I/home/papoj/Projects/qtbuild/qtbase/include -I/home/papoj/Projects/qtbuild/qtbase/include/QtCore -I/home/papoj/Projects/qt-everywhere-src-6.2.1/qtbase/src/corelib -I/home/papoj/Projects/qtbuild/qtbase/src/corelib -I/home/papoj/Projects/qtbuild/qtbase/src/corelib/global -I/home/papoj/Projects/qtbuild/qtbase/src/corelib/kernel -I/home/papoj/Projects/qt-everywhere-src-6.2.1/qtbase/src/corelib/../3rdparty/tinycbor/src -I/home/papoj/Projects/qtbuild/qtbase/include/QtCore/6.2.1 -I/home/papoj/Projects/qtbuild/qtbase/include/QtCore/6.2.1/QtCore -I/home/papoj/Projects/qt-everywhere-src-6.2.1/qtbase/src/corelib/../3rdparty/double-conversion/double-conversion -I/home/papoj/Projects/qt-everywhere-src-6.2.1/qtbase/src/corelib/../3rdparty/double-conversion -I/home/papoj/Projects/qt-everywhere-src-6.2.1/qtbase/src/corelib/../3rdparty/forkfd -I/home/papoj/Projects/qtbuild/qtbase/src/corelib/.rcc -I/home/papoj/Projects/qt-everywhere-src-6.2.1/qtbase/mkspecs/win32-g++ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/home/papoj/Projects/qtbuild/qtbase/src/xml/Xml_autogen/include -I/home/papoj/Projects/qtbuild/qtbase/include/QtXml -I/home/papoj/Projects/qt-everywhere-src-6.2.1/qtbase/src/xml -I/home/papoj/Projects/qtbuild/qtbase/src/xml -I/home/papoj/Projects/qtbuild/qtbase/include/QtXml/6.2.1 -I/home/papoj/Projects/qtbuild/qtbase/include/QtXml/6.2.1/QtXml -I/home/papoj/Projects/qt-everywhere-src-6.2.1/qtbase/src/tools/bootstrap/.. -I/home/papoj/Projects/qt-everywhere-src-6.2.1/qtbase/src/tools/bootstrap/../../3rdparty/tinycbor/src -DNDEBUG -O2 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -ffunction-sections -fdata-sections -mshstk -Wsuggest-override -std=gnu++17 -MD -MT qtbase/src/tools/bootstrap/CMakeFiles/Bootstrap.dir/__/__/corelib/global/qglobal.cpp.o -MF qtbase/src/tools/bootstrap/CMakeFiles/Bootstrap.dir/__/__/corelib/global/qglobal.cpp.o.d -o qtbase/src/tools/bootstrap/CMakeFiles/Bootstrap.dir/__/__/corelib/global/qglobal.cpp.o -c /home/papoj/Projects/qt-everywhere-src-6.2.1/qtbase/src/corelib/global/qglobal.cpp In file included from /home/papoj/Projects/qt-everywhere-src-6.2.1/qtbase/src/corelib/global/qglobal.cpp:41: /home/papoj/Projects/qt-everywhere-src-6.2.1/qtbase/mkspecs/win32-g++/qplatformdefs.h:55:10: fatal error: tchar.h: No such file or directory 55 | #include <tchar.h> | ^~~~~~~~~
I suspect that CMake, for some reason, ignore my "CROSS_COMPILE" option and uses Linux c++ tool to compile instead of 'x86_64-w64-mingw32-g++', but I dont know how to fix that. I saw setting flag "-device-option CROSS_COMPILE=.*" in at least few articles/stackoverflow threads about cross-compiling Qt.
Also I'm not sure if I understand flag 'qt-host-path' correctly - should it point to path where I compiled Qt 6.2.1 for Linux using GCC? Or this should be win MinGW Qt build?
Hope this is not trivial and stupid question. Thanks!
-
@papoj
the device-option/CROSS_COMPILE way is the old way for qmake cross builds. With CMake you have to provide a CMake toolchain file.
See this: https://doc.qt.io/qt-6/configure-linux-device.html
Its for Linux cross compilation, but it shows how to specify the CMake toolchain file. -
Thanks for your answer @raven-worx - I've compiled qt6 finally (after some additional troubles :D).
But now I'm again lost a little bit - I got qmake.exe as a result (and many more, anyway), so I cannot choose this as "Qt version" in Qt Creator on Linux, to build Qt app for Windows (because of .exe).
As mentioned here: https://forum.qt.io/topic/94742/cross-compile-and-deploy-from-linux-to-windows I have MinGW for Linux and Qt6 compiled with that MinGW. Can I connect those two somehow to get app exe for Windows?Thanks again!
-
@papoj
did you specifyQT_BUILD_TOOLS_WHEN_CROSSCOMPILING
? If so you should have a script calledhost-qmake
. I currently dont know if QtCreator accecpts any executables other than exactlyqmake
.
Thehost-qmake
points to your mingw compiled Qt. Also take a look intoqt.conf
Also read this whole article: https://www.qt.io/blog/qt-6-build-system -
@raven-worx thanks again, hope I'm not annoying (at least yet :D).
Indeed I have host-qmake script in my build path.#!/bin/sh # The directory of this script is the expanded absolute path of the "$qt_prefix/bin" directory. script_dir_path=`dirname $0` script_dir_path=`(cd "$script_dir_path"; /bin/pwd)` /home/papoj/Qt/6.2.1/gcc_64/bin/qmake -qtconf "$script_dir_path/target_qt.conf" $*
I tried to use this host-qmake to generate new .pro file (with flag -project) and with already existing .pro file from my project. In both cases output was same:
Info: creating stash file /home/papoj/Projects/SampleProject/.qmake.stash Project ERROR: Cannot run target compiler 'g++'. Output: =================== g++: error: command line option '-fno-keep-inline-dllexport' is not supported by this configuration Using built-in specs. COLLECT_GCC=g++ OFFLOAD_TARGET_NAMES=nvptx-none:hsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) =================== Maybe you forgot to setup the environment?
-fno-keep-inline-dllexport flag is not available with g++ (but is available with x86_64-w64-mingw32-g++). Also --host points to good platform, but --target not - it should be win32 (or something with Windows).
I tried to find qt.conf file in my whole "Projects" directory. I've found it only in source code for Qt 6.2.1 and in mingw81_64 directory copied from Windows. But there is target_qt.conf in my Qt build directory.[Paths] Prefix=../ HostPrefix=../../../Qt/6.2.1/gcc_64 HostData=../../../Projects/qt6 Sysroot= SysrootifyPrefix=false TargetSpec=win32-g++ HostSpec=linux-g++
Looks fine, especially TargetSpec=win32-g++.
Did I miss something? I read that article about build system for a few times and I did not find anything which could help in this situation, but maybe I don't understand something or understand it wrongly.
-
@papoj said in Qt6 cross compile for Windows:
But there is target_qt.conf in my Qt build directory.
yes thats the one i meant (and which is referenced in the host-qmake script).
TheTargetSpec=win32-g++
means that qmake looks for a "win32-g++" mkspec folder in <host-qt6>/qtbase/mkspecsI didnt know that you intent to use qmake rather than cmake as your build system.
So you have 2 options from here:- again compile Qt6 with the cmake toolchain option AND the old parameters (
-platform linux-gcc-64 -xplatform win32-g++ -device-option CROSS_COMPILE=...
). I think this should still work for all qmake dependent stuff. - manually edit
<host-qt6>/qtbase/mkspecs/win32-g++/qmake.conf
to call your correct mingw cross-compiler
- again compile Qt6 with the cmake toolchain option AND the old parameters (
-
@raven-worx thanks! Everything works now, I had to do both options mentioned by you. This time CMake did not return any warning with "QT_QMAKE_DEVICE_OPTIONS" - maybe it need to be mixed together with CMake toolchain, idk.