Qt for Windows - Building from Source
Qt for Windows-从源代码构建
This page describes the process of configuring and building Qt for Windows. Before building, there are some requirements that are given in more detail in the Qt for Windows - Requirements document.
此页面描述了为Windows配置和构建Qt的过程。在构建之前,Qt for Windows-需求文档中更详细地给出了一些要求。
You can download the Qt 5 sources from the Downloads page. For more information, visit the Getting Started with Qt page.
可以从下载页面下载Qt 5源代码。有关更多信息,请访问Qt入门页面。
Step 1: Install the License File (Commercially Licensed Qt Only)
步骤1:安装许可证文件(仅限商业许可的Qt)
If you use Qt with a commercial license, the Qt tools look for a local license file. If you are using a binary installer or the commercial Qt Creator, your licenses are automatically fetched and stored in your local user profile (%USERPROFILE%\AppData\Roaming\Qt\qtlicenses.ini
file).
如果使用带有商业许可证的Qt,Qt工具会查找本地许可证文件。如果使用的是二进制安装程序或商用Qt Creator,许可证将自动获取并存储在本地用户配置文件中(%USERPROFILE%\AppData\Roaming\Qt\qtlicenses.ini文件)。
If you do not use any binary installer or Qt Creator, you can download the respective license file from your Qt Account Web portal and save it to your user profile as %USERPROFILE%\.qt-license
. If you prefer a different location or file name, you need to set the QT_LICENSE_FILE
environment variable to the respective file path.
如果不使用任何二进制安装程序或Qt Creator,可以从Qt帐户门户网站下载相应的许可证文件,并将其作为%USERPROFILE%\.qt-license
保存到用户配置文件中。如果希望使用其他位置或文件名,则需要将QT_LICENSE_FILE
环境变量设置为相应的文件路径。
Step 2: Unpack the Archive
第二步:打开存档
Uncompress the files into the directory you want Qt installed; e.g. C:\Qt\%VERSION%
.
将文件解压缩到要安装Qt的目录中;例如C:\Qt\%VERSION%。
Note: The install path must not contain any spaces or Windows specific file system characters.
注意:安装路径不得包含任何空格或Windows特定的文件系统字符。
Step 3: Set the Environment Variables
步骤3:设置环境变量
We recommend creating a desktop link that opens a command prompt with the environment set up similar to the Command Prompt menu entries provided by Visual Studio. This is done by creating an application link passing a .cmd
file setting up the environment and the command line option /k
(remain open) to cmd.exe
.
我们建议创建一个桌面链接,打开一个命令提示符,其环境设置类似于Visual Studio提供的命令提示符菜单项。这是通过创建一个应用程序链接来实现的,该链接将一个.cmd文件传递给cmd.exe,该文件设置了环境和命令行选项/k(保持打开状态)。
Assuming the file is called qt5vars.cmd
and the Qt folder is called Qt-5
and located under C:\Qt
:
假设文件名为qt5vars.cmd,Qt文件夹名为Qt-5,位于C:\Qt下:
REM Set up Microsoft Visual Studio 2017, where <arch> is amd64, x86, etc.
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvarsall.bat" <arch>
SET _ROOT=C:\Qt\Qt-5
SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
REM Uncomment the below line when using a git checkout of the source repository
REM SET PATH=%_ROOT%\qtrepotools\bin;%PATH%
SET _ROOT=
A desktop link can then be created by specifying the command %SystemRoot%\system32\cmd.exe /E:ON /V:ON /k C:\Qt\qt5vars.cmd
as application and C:\Qt\Qt-5
as working directory.
然后,可以通过指定命令%SystemRoot%\system32\cmd.exe /E:ON /V:ON /k C:\Qt\qt5vars.cmd
作为应用程序,C:\Qt\ Qt-5作为工作目录来创建桌面链接。
Note: Setups for MinGW are similar; they differ only in that the
bin
folder of the installation should be added to the path instead of calling the Visual Studio setup script. For MinGW, please make sure that nosh.exe
can be found in the path, as it affectsmingw32-make
.
注:MinGW的设置类似;它们的不同之处仅在于,应将安装的bin文件夹添加到路径中,而不是调用Visual Studio安装脚本。对于MinGW,请确保在路径中找不到sh.exe,因为它会影响mingw32 make。
Settings required by the additional libraries (see Qt for Windows - Requirements) should also go this file below the call to the Windows SDK setup script.
附加库所需的设置(请参阅Qt for Windows-要求)也应放在Windows SDK安装脚本调用下方的此文件中。
Step 4: Build the Qt Library
步骤4:构建Qt库
The default behavior of configure is to create an in-source build of Qt 5. If you want to install Qt 5 to a separate location, you need to specify the command line option -prefix <location>
. Alternatively, the command line option -developer-build
creates an in-source build for developer usage.
configure的默认行为是创建Qt 5的源代码内版本。如果想将Qt 5安装到单独的位置,需要指定命令行选项-prefix <location>
。或者,命令行选项-developer-build
创建了一个源代码内构建供开发人员使用。
To configure the Qt library for a debug build for your machine, type the following command in the command prompt:
要为计算机的调试版本配置Qt库,请在命令提示符下键入以下命令:
configure -debug -nomake examples -nomake tests -skip qtwebengine -opensource
The Configure Options page contains more information about the configure options.
配置选项页面包含有关配置选项的更多信息。
To build Qt using jom, type:
要使用jom构建Qt,请键入:
jom
If you do not have jom installed, type:
如果没有安装jom,请键入:
nmake
For MinGW, type:
对于MinGW,请键入:
mingw32-make
If an installation prefix was given, type jom install
, nmake install
or mingw32-make install
.
如果给出了安装前缀,请键入jom install、nmake install或mingw32 make install。
Note: If you later need to reconfigure and rebuild Qt from the same location, ensure that all traces of the previous configuration are removed by entering the build directory and typing
nmake distclean
before runningconfigure
again.注意:如果以后需要从同一位置重新配置和重构建Qt,请确保在再次运行configure之前,通过进入构建目录并键入nmake distclean来删除之前配置的所有痕迹。
Parallel Builds
并行构建
jom is a replacement for nmake
which makes use of all CPU cores and thus speeds up building.
jom是nmake的替代品,nmake利用所有CPU内核,从而加快了构建速度。
Step 5: Build the Qt Documentation
步骤5:构建Qt文档
For the Qt reference documentation to be available in Qt Assistant, you must build it separately:
为了在Qt Assistant中提供Qt参考文档,必须单独构建它:
nmake docs
This will build the documentation in the build folder. If you have installed Qt in a separate location, you will also need to install the documentation:
这将在构建文件夹中构建文档。如果在单独的位置安装了Qt,还需要安装文档:
nmake install_docs
© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.