Qt 5.12.12 静态编译(MinGW)

前置准备

系统环境

版本	Windows 11 专业版
版本	22H2
安装日期	‎2023/‎6/‎18
操作系统版本	22621.2428
体验	Windows Feature Experience Pack 1000.22674.1000.0

依赖工具

gcc

Qt 5.12.12 安装 MinGW 后自动安装
https://download.qt.io/archive/qt/5.12/5.12.12/qt-opensource-windows-x86-5.12.12.exe
MinGW
gcc

Perl

https://www.perl.org/get.html​ 下载 Strawberry Perl,并安装
perl

Python

https://www.python.org/downloads/

python

Qt 源码(5.12.12)

https://download.qt.io/archive/qt/5.12/5.12.12/single/qt-everywhere-src-5.12.12.zipqt-source-code

开始编译

源码准备

将上述下载的 qt-everywhere-src-5.12.12.zip 源码解压至 D:\Qt\qt-everywhere-src-5.12.12 目录

生成编译文件

cd D:\Qt\qt-everywhere-src-5.12.12

configure.bat -static -release -platform win32-g++ -opensource -confirm-license -prefix "D:\Qt\Qt5.12.12\5.12.12\mingw73_64_static" -qt-zlib -qt-libpng -qt-webp -qt-libjpeg -qt-freetype  -no-opengl -skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtlocation -skip qtlottie -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquick3d -skip qtquickcontrols -skip qtquickcontrols2 -skip qtquicktimeline -skip qtremoteobjects -skip qtscript -skip qtsensors -skip qtspeech -skip qtsvg -skip qtwayland -skip qtwebglplugin -skip qtwebview -skip webengine -make libs -nomake tools -nomake examples -nomake tests

# 上述命令中 D:\Qt\Qt5.12.12\5.12.12\mingw73_64_static 为需要安装的目录

编译

mingw32-make -j16

# 使用 16 个线程编译

安装

mingw32-make install

make install

修改 conf 文件

修改安装目录下的 mkspecs\common\g++-win32.conf,例:D:\Qt\Qt5.12.12\5.12.12\mingw73_64_static\mkspecs\common\g++-win32.conf
g++-win32.conf

  • 新增 QMAKE_LFLAGS = -static
  • QMAKE_LFLAGS_DLL = -shared 修改为 QMAKE_LFLAGS_DLL = -static
    static

Qt Creator 配置

添加 Qt 版本

打开 工具 > 选项
选项
Kits 中选择 Qt Versions添加 刚才编译安装的 qmake
qmake

添加套件

Kits 选择一个套件(MinGW 64-bit)进行克隆
然后选择克隆后的套件,修改 Qt version 为刚才编译安装的版本
kits

测试

在项目中选择刚刚添加的套件,进行 build
build

编译结果
结果

参考

  • https://blog.51cto.com/DreamLife/5357055 Qt 静态编译(5.15.2 MinGW 32-bit)
  • https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW Building a static Qt for Windows using MinGW
  • https://tadeubento.com/2020/qt-static-builds-under-windows/ Qt: Static Builds Under Windows
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈挨踢

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值