本文介绍如何使用MSVC编译Qt 5.13.2版本的静态库.
1. 下载qt-everywhere-src-5.13.2
Qt离线下载地址:http://download.qt.io/archive/qt/
下载完成之后,解压到D:\Qt-5.13.2\qt-everywhere-src-5.13.2
目录。
2. 配置环境变量
将如下内容保存到qtvars.cmd
文件:
REM Set up \Microsoft Visual Studio 2017, where <arch> is \c amd64, \c x86, etc.
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
SET _ROOT=D:\Qt-5.13.2\qt-everywhere-src-5.13.2
SET PATH=%_ROOT%\qtbase;%_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=
以管理员权限打开命令提示符,运行qtvars.cmd
文件,运行完之后,不要关闭命令提示符,后面的命令都要在该命令提示符下完成。
3. configure命令
在命令行中进入D:\Qt-5.13.2\qt-everywhere-src-5.13.2
目录,执行如下configure命令:
configure -prefix D:\Qt-5.13.2\msvc2017_x86_static -static -static-runtime -debug-and-release -platform win32-msvc -opensource -confirm-license -force-debug-info -strip -qt-harfbuzz -qt-freetype -qt-zlib -qt-libpng -qt-libjpeg -qt-pcre -nomake examples -nomake tests -no-dbus -skip qtwebengine -openssl-linked -no-opengl -I C:\OpenSSL-Win32\include -L C:\OpenSSL-Win32\lib
关于configure各个参数的含义可以查看帮助文档:configure --help
C:\OpenSSL-Win32
中存放OpenSSL的头文件和静态库文件,目录结构如下:
C:\OpenSSL-Win32\
├─include
│ └─openssl
│ aes.h
│ asn1.h
│ .......
│ .......
└─lib
libcrypto.lib
libssl.lib
4. 编译、安装
configure完成以后,使用nmake
命令编译,最后使用nmake install
命令将生成文件安装到D:\Qt-5.13.2\msvc2017_x86_static
目录。