Skip to content
Advertisement

How to cross-compile Qt6 on Linux for Windows?

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, so I have to do this cross-compilation.

My configure cmd:

JavaScript

At the end of CMake work I’m getting this:

JavaScript

And then, after cmake –build . –parallel:

JavaScript

I have checked (this is also visible in log above) and 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.

Does anybody cross-compiled Qt6 for Windows on Linux manually? I cannot find any working solution on the Internet.

Advertisement

Answer

For those coming here from google with same problem.

In Qt6 you need to specify Cmake toolchain for cross-compilation (I get something similar to toolchain shared here), as ‘alone’ device-option CROSS_COMPILE (as in cmd from my question) is depreciated/outdated (or smth like that).

In my case I needed to use CMake toolchain and device-option CROSS-COMPILE as well, because in other way qmake was not able to find proper cross-platform compiler (in my case x86_64-w64-mingw32-g++-posix). To use compiler with “posix” at the end I needed to modify qtbase/mkspecs/win32-g++/qmake.conf. This is how it looks like after changes:

JavaScript

Final ./configure cmd:

JavaScript

After cmake –build and cmake –install I got host-qmake script in my build path

$HOME/Projects/testing_qt_builds/qtbuild_with_old_params/bin/

Which I had to use to build my Qt project by passing .pro file to it. And then I just copied .exe file to Windows, provided all needed dlls and POOF, app works. 😀

My thread on qt forum with same problem where one of moderators helped me a lot to get final solution.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement