1.背景
以前使用MFC做界面,但是美化开发成本高,难度大,而且效果不理想,所以想采用QT实现。同时使用现有的dll库方式打包输出,依赖库大,而且输出文件多。所以通过静态最小编译的方式。实现输出单一最小UI exe模块。
2.源码选择和版本
编译源文件选择市面上版本比较稳定的是5.12.10。需要下载QT源码和程序,进入
QT版本下:
https://download.qt.io/archive/qt/ 进入版本,选择single
qt源码版本:http://mirrors.ustc.edu.cn/qtproject/archive/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.tar.xz
https://blog.csdn.net/skyloveka/article/details/108130252
2.QT剪裁
https://blog.csdn.net/ZCShouCSDN/article/details/76037463
参数含义:https://blog.csdn.net/kunkliu/article/details/79149371
2.编译环境搭建
编译工具安装
编译需要的环境可以看官方文档,windows-requirements 中的Building from Source
有说明需要安装的工具,所有工具都记得要添加到环境变量。
Qt5-12-5-static-build-2020-07-11-22-37-34
- VS2019(其他版本仅作参考),下载地址:Visual Studio 2019
- ActivePerl, 下载地址:Download And Install Perl: ActivePerl
- Python,下载地址:Python Releases for Windows
- Ruby(以前的官方文档是有的,如果有问题可以装下),下载地址:RubyInstaller for Windows
- Jom,多核编译,下载地址:jom releases
3.编译准备
- 源码下载并解压,下载地址:qt-everywhere-src-5.12.5.zip
- 在源码同级目录创建个 qt-build 目录来放生成的文件,也就是使用
shadow build
,方便修改配置后进行多配置编译。直接运行源码目录下的 configure.bat 会把生成文件生成到源码目录,修改配置后编译容易出错。
.\..\src\configure.bat -static -release -platform win32-msvc -release -static -prefix "D:\Qt\Qt5.12.5-msvc2019-x86-static-release-full" -opensource -confirm-license -nomake examples -nomake tests -plugin-sql-sqlite -plugin-sql-odbc -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -mp
jom
nmake install
4.编译命令
"..\src\configure.bat" -static -debug-and-release -platform win32-msvc -release -static -prefix "D:\Qt\Q6.1.0-msvc2019-x64-static-release-full" -opensource -confirm-license -nomake examples -nomake tests -plugin-sql-sqlite -plugin-sql-odbc -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -m
"../qt-everywhere-src-5.12.10/configure.bat" -static\
-debug-and-release -platform win32-msvc\
-no-opengl -prefix "D:\Qt\Qt5.12.10-msvc2019-x64-static-md-release-mini"\
-opensource -confirm-license -make libs -nomake tools \
-nomake examples -nomake tests -skip qt3d \
-skip qtandroidextras -skip qtcanvas3d \
-skip qtconnectivity -skip qtdatavis3d \
-skip qtdeclarative -skip qtdoc \
-skip qtgamepad -skip qtcharts \
-skip qtgraphicaleffects \
-skip qtimageformats -skip qtlocation \
-skip qtmacextras -skip qtmultimedia \
-skip qtnetworkauth -skip qtpurchasing \
-skip qtquickcontrols -skip qtquickcontrols2 \
-skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtspeech
-skip qtsvg -skip qttools -skip qttranslations -skip qtvirtualkeyboard \
-skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets \
-skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns \
-no-feature-texthtmlparser -no-feature-textodfwriter -no-feature-concurrent \
-no-feature-effects -no-feature-sharedmemory -no-feature-systemsemaphore \
-no-feature-im -no-feature-dom -no-feature-filesystemwatcher -no-feature-graphicsview \
-no-feature-graphicseffect -no-feature-sizegrip -no-feature-printpreviewwidget \
-no-feature-keysequenceedit -no-feature-colordialog -no-feature-fontdialog -no-feature-printpreviewdialog \
-no-feature-progressdialog -no-feature-errormessage -no-feature-wizard -no-feature-datawidgetmapper \
-no-feature-cups -no-feature-paint_debug -no-feature-codecs -no-feature-big_codecs -no-feature-iconv \
-no-feature-networkproxy -no-feature-socks5 -no-feature-networkdiskcache -no-feature-bearermanagement \
-no-feature-mimetype -no-feature-undocommand -no-feature-undostack -no-feature-undogroup \
-no-feature-undoview -no-feature-statemachine -no-feature-gestures -no-feature-dbus \
-no-feature-sessionmanager -no-feature-topleveldomain -no-feature-sha3-fast -no-feature-imageformat_ppm \
-no-feature-imageformat_xbm -no-feature-freetype -no-feature-appstore-compliant -no-feature-process
-no-feature-lcdnumber -qt-zlib -qt-libpng -qt-libjpeg -no-sql-driver -no-zlib -no-webkit -no-openssl -no-gif -no-phonon -no-qt3support \
-no-sqlite -no-largefile -no-exceptions
Qt5-12-5-static-build-2020-07-11-22-47-19
- 修改
qtbase\mkspecs\common\msvc-desktop.conf
文件,将 MD 改为 MT
Qt5-12-5-static-build-2020-07-12-00-27-17
- 打开 VS 的命令行工具并切换到第 2 步创建的 qt-build 目录,后面就是输入命令编译了。
Qt5-12-5-static-build-2020-07-12-00-29-11
https://www.jianshu.com/p/192cfe3d9b30
VS2017编译32位/64位QT静态库 https://blog.csdn.net/weixin_35857412/article/details/94738666