0 参考
QT最新版5.14在WINDOWS环境静态编译安装和部署的完整过程 VS 2019-QT STATIC LINK BUILD WINDOWS 32 BIT/64 BIT
MSVC 静态编译 Qt 5
Win7下静态编译QT5.12源码
Building Qt 5 from Git
1 获取源码
试过通过官网的MaintenanceTool,还有git获取的源码,编译时总是有报错,最后试着从清华源获取源码,成了。
https://mirrors.tuna.tsinghua.edu.cn/qt/archive/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.zip
2 编译工具
源码路径下的README文件中有编译方式的说明,其中列出来Windows下编译所需工具
Windows:
--------
Open a command prompt.
Ensure that the following tools can be found in the path:
* Supported compiler (Visual Studio 2012 or later,
MinGW-builds gcc 4.9 or later)
* Perl version 5.12 or later [http://www.activestate.com/activeperl/]
* Python version 2.7 or later [http://www.activestate.com/activepython/]
* Ruby version 1.9.3 or later [http://rubyinstaller.org/]
python需要python2,python3不行,下面是我的版本
This is perl 5, version 32, subversion 1 (v5.32.1) built for MSWin32-x64-multi-thread
Python 2.7.18
ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x64-mingw32] (strawberry-perl-5.32.1.1-64bit)
如果安装有问题或者环境变量有问题之后configure配置时会报warning
3 修改\qt-everywhere-src-5.15.2\qtbase\mkspecs\common\msvc-desktop.conf
将文件中-MD 全改为 -MT(3处)
4 configure配置
打开x64 Native Tools Command Prompt for VS 2019(打算编译成64位就打开x64,32位打开x86),
cd 到源文件文件夹
configure.bat -prefix S:\Qt\5.15.2\Qt5.15.2-static -confirm-license -opensource -debug-and-release -static -static-runtime -angle -combined-angle-lib -no-feature-d3d12 -platform win32-msvc -mp -nomake tests -nomake examples -nomake tools -skip qtwebengine -skip qtwebview
参数的具体含义参考博客里说的非常详细,这里就不贴了,请自己根据需求调整。
configure -h指令可以查看允许的参数与简介
完成时会显示结果(warning,如果有的话)与下一步指示
Qt is now configured for building. Just run 'nmake'.
Once everything is built, you must run 'nmake install'.
Qt will be installed into '设定的编译结果路径'.
5 编译
继续运行nmake,需要等待比较长的时间。
当nmake完成时,继续运行nmake install,完成时就结束了。
6 添加到Qt Creator
我是用MaintenanceTool下载的Qt Creator
https://www1.qt.io/download-open-source-access/
工具-选项-Kits-Qt Versions
点击添加,找的编译结果目录bin中的qmake.exe,
会给一个找不到qmlscene.exe的警告,我的解决方案是去别的库(可以用MaintenanceTool下载)bin目录下复制个过来。
工具-选项-Kits-kits
设置好 名称,Compiler(64还是32由编译方式决定),Qt Version(上一步刚刚添加的版本)
简单写个程序测试下