How-to-Cross-Compile-Qt6-Application-to-Windows-Application-in-Linux-Platform
why
Im working on wsl2, having got used to Jetbrains Tools,
so I use clion to develop qt program instead of qtcreator
the program I am working on is targeted at not-tech-people ,
so I need release it on windows
how-to-do-it
env:archlinux on wsl2 ,clion
basic install
- mingw-w64-cmake
- mingw-w64-g++
- qt6-base (which is avaliable on archlinux,or you can use online installer)
- get qt6 mingw package(which I used online installer for windows,and got it in “C:\Qt\6.7.2\mingw_64”,and copy it to ~/qt)
config
- create a qt6 project
- config toolchain of clion using mingw-w64-cmake,mingw-w64-g++
fix problem one :qt6 package not found
add cmake param
-DCMAKE_TOOLCHAIN_FILE=~/qt/lib/cmake/Qt6/qt.toolchain.cmake
fix problem two: conflict between host-headers and mingw-headers
add cmake param
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,-undefined"
add in CMakeLists.txt
set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)
set(CMAKE_SYSROOT "/usr/x86_64-w64-mingw32/")
refer
if that fails try to swap the position of the two params
fix problem three: missing dlls
using package tool in ~/qt/bin/windeployqt6.exe ,because I am using wsl2,
I can run it directly,as this
windeployqt6.exe PROJECT/WIN_BUILD/XXX.exe
if it still remind you the missing dll ,find them in /usr/x86_64-w64-mingw32/bin/,copy them to the same dir as XXX.exe
fix problem four: the black console appears when the app run in windows
edit CMakeLists.txt, pay attention to postion of WIN32
add_executable(PROJECT WIN32
main.cpp )