windows下Qt5.15.2源码编译

本文详细记录了在Windows11环境下,使用VS2015编译Qt5.15.2源码的过程,包括所需依赖、配置选项以及编译和安装步骤。重点介绍了configure命令的参数设置,如编译模式、库选择等,并提醒注意避开路径含有空格或中文的常见错误。最后,文章提到了nmake编译和nmakeinstall的使用,以完成Qt的安装。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

记录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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值