Qt5 MSVC 静态编译
Qt5 MSVC 静态编译
要求
提示:确保 Perl 在 Git 之前添加到系统环境变量 PATH 中,否则将会用到过时的版本 (Perl 5.8),从而导致脚本运行失败。
下载源码包
这里以 5.12.12 为例:
https://download.qt.io/archive/qt/5.12/5.12.12/single/qt-everywhere-src-5.12.12.zip
编译
编译需要使用 jom
工具,位置在 Qt 安装目录下的 Tools\QtCreator\bin\jom
中,将这个目录添加到系统环境变量 PATH
中。
解压 qt-everywhere-src-5.12.12.zip
,并在同级目录下创建 build
目录:
temp-directory
├── build
└── qt-everywhere-src-5.12.12
从开始菜单选择 Visual Studio 2017/适用于 VS 2017 的 x64 本机工具命令提示
(32 位请选择 x86 版本)
如果需要编译 Qt Web Engine 模块,请先查看 编译 Qt Web Engine 小节内容。
进入 build
目录进行构建
cd build
set Path=%Path%;..\qt-everywhere-src-5.12.12\gnuwin32\bin
..\qt-everywhere-src-5.12.12\configure.bat -static -prefix "D:\Develop\Qt5.12.12\5.12.12\msvc2017_64_static" -confirm-license -opensource -debug-and-release -platform win32-msvc -nomake examples -nomake tests -plugin-sql-sqlite -plugin-sql-odbc -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -mp -skip qtwebengine
jom -j
jom install -j
-prefix
为安装路径
jom -j
:编译时使用多线程,加快编译速度
注意:命令中加入
-skip qtwebengine
代表不编译 Web Engine ,想编译的话先看 编译 Qt Web Engine 小节内容再删掉此参数
使用
经过 jom -j 16 install
后,此时静态编译工具已被安装到 D:\Develop\Qt5.12.12\5.12.12\msvc2017_64_static
。
打开 Qt Creator ,菜单栏选择 工具 - 选项
,Kits - Qt Versions
中点击 添加...
,选择 D:\Develop\Qt5.12.12\5.12.12\msvc2017_64_static\bin\qmake.exe
后点击确定。
之后在 Kits
中选中你常用的 Kit
,点击 克隆(Clone)
后在 Qt version
中选择你之前设置的版本。
最后使用此 Kit
即可。
补充
编译 Qt Web Engine
提醒:编译 Web Engine 所需时间极长!!!
在 MSVC 2017 命令行工具中,cd 到 qt-everywhere-src-5.12.12\qtwebengine
目录下
cd qt-everywhere-src-5.12.12\qtwebengine
set Path=%Path%;\qt-everywhere-src-5.12.12\gnuwin32\bin
64 位:
"D:\Develop\Qt5.12.12\5.12.12\msvc2017_64\bin\qmake.exe" -- -webengine-proprietary-codecs
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\Hostx64\x64\nmake.exe"
32 位:
"D:\Develop\Qt5.12.12\5.12.12\msvc2017_32\bin\qmake.exe" -- -webengine-proprietary-codecs
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\Hostx86\x86\nmake.exe"