Skip to content

Instantly share code, notes, and snippets.

@iaoedsz2008
Last active August 21, 2022 11:12
Show Gist options
  • Save iaoedsz2008/89f7ea9490c9b9de4ffab7d98c2eb8b6 to your computer and use it in GitHub Desktop.
Save iaoedsz2008/89f7ea9490c9b9de4ffab7d98c2eb8b6 to your computer and use it in GitHub Desktop.
【Windows】Qt静态编译

Qt库静态编译

伸手党可以直接下载本人编译好的Qt512Qt513Qt514Qt515Qt63

下载Qt源码

以下命令都是在Visual Studio提供的Command Prompt中进行

Qt6(未测试)

Qt6需要使用Visual Studio 2019Visual Studio 2022

Qt6编译需要安装Strawberry Perl,并添加到PATH环境变量

Qt6编译需要安装CMake,并添加到PATH环境变量

官方文档:Building from SourceConfigure Options

Qt 6.3.1

SET _ROOT=D:\qt-everywhere-src-6.3.1
SET PATH=%_ROOT%\qtbase\bin;%PATH%
SET _ROOT=

configure -confirm-license -debug-and-release -nomake examples -nomake tests -opengl desktop -opensource -qt-freetype -qt-libjpeg -qt-libpng -qt-pcre -qt-sqlite -qt-zlib -skip qtwebengine -static -static-runtime -strip -prefix D:\Qt63

cmake --build . --parallel
cmake --install .

Qt 6.2.4

SET _ROOT=D:\qt-everywhere-src-6.2.4
SET PATH=%_ROOT%\qtbase\bin;%PATH%
SET _ROOT=

configure -confirm-license -debug-and-release -nomake examples -nomake tests -opengl desktop -opensource -qt-freetype -qt-libjpeg -qt-libpng -qt-pcre -qt-sqlite -qt-zlib -skip qtwebengine -static -static-runtime -strip -prefix D:\Qt62

cmake --build . --parallel
cmake --install .

Qt 6.1.2

SET _ROOT=D:\qt-everywhere-src-6.1.3
SET PATH=%_ROOT%\qtbase\bin;%PATH%
SET _ROOT=

configure -confirm-license -debug-and-release -nomake examples -nomake tests -opengl desktop -opensource -qt-freetype -qt-libjpeg -qt-libpng -qt-pcre -qt-sqlite -qt-zlib -skip qtwebengine -static -static-runtime -strip -prefix D:\Qt61

cmake --build . --parallel
cmake --install .

Qt 6.0.4

SET _ROOT=D:\qt-everywhere-src-6.0.4
SET PATH=%_ROOT%\qtbase\bin;%PATH%
SET _ROOT=

configure -confirm-license -debug-and-release -nomake examples -nomake tests -opengl desktop -opensource -qt-freetype -qt-libjpeg -qt-libpng -qt-pcre -qt-sqlite -qt-zlib -skip qtwebengine -static -static-runtime -strip -prefix D:\Qt60

cmake --build . --parallel
cmake --install .

Qt5

Qt5使用Visual Studio 2017

Qt5使用jom替代nmake以使用多进程编译,把jom解压到PATH环境变量能找到的任何位置即可

官方文档:Building from SourceConfigure Options

尽量不要使用5.14.1之前的版本,因为存在问题72903780037882779090

Qt 5.15.5

SET _ROOT=D:\qt-everywhere-src-5.15.5
SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
SET _ROOT=

configure -confirm-license -debug-and-release -nomake examples -nomake tests -opengl desktop -opensource -qt-freetype -qt-libjpeg -qt-libpng -qt-pcre -qt-sqlite -qt-zlib -skip qtwebengine -static -static-runtime -strip -prefix D:\Qt515

jom -j32
jom -j32 install

Qt 5.14.2

SET _ROOT=D:\qt-everywhere-src-5.14.2
SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
SET _ROOT=

configure -confirm-license -debug-and-release -nomake examples -nomake tests -opengl desktop -opensource -qt-freetype -qt-libjpeg -qt-libpng -qt-pcre -qt-sqlite -qt-zlib -skip qtwebengine -static -static-runtime -strip -prefix D:\Qt514

jom -j32
jom -j32 install

Qt 5.13.2

SET _ROOT=D:\qt-everywhere-src-5.13.2
SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
SET _ROOT=

configure -confirm-license -debug-and-release -nomake examples -nomake tests -opengl desktop -opensource -qt-freetype -qt-libjpeg -qt-libpng -qt-pcre -qt-sqlite -qt-zlib -skip qtwebengine -static -static-runtime -strip -prefix D:\Qt513

jom -j32
jom -j32 install

5.13及更老的版本由于存在前面提到的问题,我是用如下方式解决的

D:\Qt513目录下全文搜索Windows Kits得到类似以下绝对路径

"C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.19041.0\\um\\x64/gdi32.lib"
C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.19041.0\\um\\x64/gdi32.lib

打开Sublime Text使用Ctrl+Shift+F打开全局替换窗口

开启Regular expression正则表达式选项

Find中输入根据绝对路径转换后的正则表达式(先替换带双引号的绝对路径)

"C:\\\\Program Files \(x86\)\\\\Windows Kits\\\\10\\\\lib\\\\10.0.19041.0\\\\um\\\\x64[/\\\\](\w+\.lib)"

Where中填写编译输出的路径

D:\Qt513

Replace中输入捕获的子表达式

$1

点击Replace

再来一次不带双引号的正则表达式

C:\\\\Program Files \(x86\)\\\\Windows Kits\\\\10\\\\lib\\\\10.0.19041.0\\\\um\\\\x64[/\\\\](\w+\.lib)

Replace中输入捕获的子表达式

$1

点击Replace

点击Save All后再Close All Files即可

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment