2024-8-13-How-to-Cross-Compile-Qt6-Application-to-Windows-Application-in-Linux-Platform

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

  1. mingw-w64-cmake
  2. mingw-w64-g++
  3. qt6-base (which is avaliable on archlinux,or you can use online installer)
  4. 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

  1. create a qt6 project
  2. 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 )

refer

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值