记录Win11 + VS2015 编译Qt5.15.2源码
前言:
由于工作中有时候遇到Qt官网提供的dll不满足项目需求或者有没及时修复的BUG,我们需要自己编译QT源码。
系统:
1,windows11 64位
编译依赖项:
1,Python 2.7.10
2,perl 5.32.1
3,ruby 3.2.2
在官网下载最新安装包,直接安装,安装时自动将安装路径添加到系统环境变量,
特别注意:安装路径不要包含空格或中文:比如这种“C:\Program Files (x86)”, “C:\Program
Files”,因为在编译时可能因为这个问题报错。
Qt源码:
1,qt-everywhere-src-5.15.2
这里源码不推荐官网下载,因为后面编译时可能会发现缺少东西,推荐直接使用国内的镜像下载:清华大学镜像
编译:
首先在仓库上级目录新建bat文件,写入以下内容:
@echo off
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
pushd qt5
configure -prefix F:\qt\qt5\install -opensource -confirm-license -qt-sqlite -qt-pcre -qt-zlib -qt-libpng -qt-libjpeg -qt-freetype -qt-harfbuzz -opengl dynamic -skip qtwebengine -nomake tests -nomake examples -mp -release -optimize-size -strip
说明一下,这句是引用VS编译器相关环境变量的,需要跟实际安装路径一致:
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
然后就是configure命令了,可以通过 configure -h查看详细的使用说明。
这里贴一个全的文本:
- cd qtbase
- F:\qt\qt5\qtbase\configure.bat -top-level -h Usage: configure [options] [assignments]
Configure understands variable assignments like VAR=value on the
command line. Each uppercased library name (obtainable with
-list-libraries) supports the suffixes _INCDIR, _LIBDIR, _PREFIX (INCDIR=PREFIX/include, LIBDIR=PREFIX/lib),
_LIBS, and - on Windows and Darwin - _LIBS_DEBUG and _LIBS_RELEASE. E.g., ICU_PREFIX=/opt/icu42 ICU_LIBS=“-licui18n -licuuc -licudata”.It is also possible to manipulate any QMAKE_* variable, to amend the
values from the mkspec for the build of Qt itself, e.g.,
QMAKE_CXXFLAGS+=-g3.Note that the _LIBS and QMAKE_* assignments manipulate lists, so
items containing meta characters (spaces in particular) need to be
quoted according to qmake rules. On top of that, the assignments as a
whole need to be quoted according to shell rules. It is recommended to
use single quotes for the inner quoting and double quotes for the
outer quoting.Top-level installation directories: -prefix
… The
deployment directory, as seen on the target device.
[/usr/local/Qt-$QT_VERSION; qtbase build directory if
-developer-build] -extprefix… The installation directory, as seen on the host machine.
[SYSROOT/PREFIX] -hostprefix [dir] … The installation directory for build tools running on
the host machine. If [dir] is not given, the current
build directory will be used. [EXTPREFIX] -external-hostbindir… Path to Qt tools built for this machine.
Use this when -platform does not match the current
system, i.e., to make a Canadian Cross Build.Fine tuning of installation directory layout. Note that all
directories except -sysconfdir should be located under
-prefix/-hostprefix:-bindir
… Executables [PREFIX/bin] -headerdir
… Header files [PREFIX/include] -libdir…
Libraries [PREFIX/lib] -archdatadir… Arch-dependent data
[PREFIX] -plugindir… Plugins [ARCHDATADIR/plugins]
-libexecdir… Helper programs [ARCHDATADIR/bin on Windows,
ARCHDATADIR/libexec otherwise] -importdir… QML1 imports [ARCHDATADIR/imports] -qmldir
… QML2 imports [ARCHDATADIR/qml] -datadir…
Arch-independent data [PREFIX] -docdir… Documentation
[DATADIR/doc] -translationdir. Translations
[DATADIR/translations] -sysconfdir… Settings used by Qt
programs [PREFIX/etc/xdg] -examplesdir… Examples
[PREFIX/examples] -testsdir… Tests [PREFIX/tests] -hostbindir