你只需使用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