你只需使用M交叉环境(MXE)。它消除了整个过程中的痛苦:
- 得到它:
$ git clone https://github.com/mxe/mxe.git
- 安装构建依赖关系
- 为Windows构建Qt及其依赖关系和跨构建工具; 这将需要大约一个小时的快速机器与体面的互联网接入; 下载大约500MB:
$ cd mxe && make qt
- 转到您的应用程序目录并将交叉构建工具添加到PATH环境变量中:
$ export PATH=<mxe root>/usr/bin:$PATH
- 运行Qt Makefile生成器工具,然后构建:
$ <mxe root>/usr/i686-pc-mingw32/qt/bin/qmake && make
- 您应该在./release目录中找到二进制文件:
$ wine release/foo.exe
------------
% qtdeploy build windows inwhtl
ERRO[0006] failed to run command _func=RunCmd cmd="/usr/lib/mxe/usr/i686-w64-mingw32.shared/qt5/bin/qmake -query QT_INSTALL_PREFIX" dir= env= error="fork/exec /usr/lib/mxe/usr/i686-w64-mingw32.shared/qt5/bin/qmake: no such file or directory" name="query install prefix path for windows on darwin"
交叉编译环境MXE
mac to windows , ok
---------------------------------
docker pull therecipe/qt:windows_32_shared
qtdeploy -docker build windows_32_shared
教程,GOPATH环境变量不知道怎么配,没有找到教程。
https://github.com/therecipe/qt/wiki/Deploying-macOS-to-Windows-32-bit-Shared
交叉编译,总结如下:(过程曲折啊,建议仔细看官方文档和wiki,浪费了好多时间。3天,Linux和Mac,Windows都测试了,windows最难搞,不建议配置,建议使用linux开发,交叉编译到windows)
1. 安装QtCreate生成UI文件
2. 使用gouic转化*.ui --> *.go文件,界面文件转化为go源代码
3. 下载therecipe/qt docker镜像,使用命令编译
4. 编译成功的文件放置在deploy目录下
## 动态库链接和静态链接方式对比
1. 动态链接,百十个文件依赖,可执行程序1.9M,总文件体积 71MB
2. 静态链接,只生成1个exe可执行程序19MB
Deploying macOS to Windows 32 bit Static
Docker deployment
-
optional: Install Wine if you want to test your Windows application on macOS
-
Install Docker: https://download.docker.com/mac/stable/Docker.dmg
-
Share your GOPATH with docker if it isn't located in some subfolder below
/Users/
,/Volumes/
,/private/
or/tmp/
. -
Pull the target image
docker pull therecipe/qt:windows_32_static
- Deploy your application
qtdeploy -docker build windows_32_static
You should find your deployed application inside the deploy
subfolder.
https://github.com/therecipe/qt/wiki/Deploying-macOS-to-Windows-32-bit-Static
Linux to windows
-----------------------
Deploying Linux to Windows 32 bit Static
Docker deployment
-
optional: Install Wine if you want to test your Windows application on Linux
-
Install Docker: https://store.docker.com/search?offering=community&type=edition or using a package manager
-
If necessary run docker as root
-
Pull the target image
docker pull therecipe/qt:windows_32_static
- Deploy your application
qtdeploy -docker build windows_32_static
https://github.com/therecipe/qt/wiki/Deploying-Linux-to-Windows-32-bit-Static