代码改变世界

静态编译 Qt5.7.0 (含 openssl 支持)

2016-10-27 11:13  几何  阅读(4346)  评论(0编辑  收藏  举报

关于Qt静态便宜的环境等,请先参见 Win10 + VS2015 下编译 Qt5.6.0 。

首先编译 openssl 。我这里用的版本是 openssl 1.0.2j (新的1.1版本的便宜稍有不同,详见 openssl 的文档)。openssl编译的bat脚本如下:

REM Initialize env for msvc 2015 cl compiler
SET PATH=C:\Windows;C:\Windows\system32
REM Set up \Microsoft Visual Studio 2015, where <arch> is amd64, x86, etc.
CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86

REM Update include & lib to support xp win sdk 7.1A
SET PATH=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin;%PATH%
SET INCLUDE=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include;%INCLUDE%
SET LIB=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib;%LIB%
SET CL=/D_USING_V120_SDK71_;%CL%

SET PERL_DIR=C:\Perl64

SET PATH=%PERL_DIR%\bin;%PATH%

perl configure VC-WIN32 no-asm --prefix=d:/openssl/dir
ms\do_ms

nmake -f ms\nt.mak
nmake -f ms\nt.mak install

 

然后更改Qt的编译脚本,便宜时引入openssl:

REM ********** Initialize env for msvc 2015 cl compiler **********
SET PATH=C:\Windows;C:\Windows\system32
REM Set up \Microsoft Visual Studio 2015, where <arch> is amd64, x86, etc.
CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86

REM ********** Update include & lib to support xp win sdk 7.1A **********
SET PATH=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin;%PATH%
SET INCLUDE=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include;%INCLUDE%
SET LIB=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib;%LIB%
SET CL=/D_USING_V120_SDK71_;%CL%

REM ********** OpenSSL 1.0.2 **********
SET OPENSLLDIR=D:\CollabPDF\windows\vendors\openssl
SET PATH=%OPENSLLDIR%\bin;%PATH%
SET INCLUDE=%OPENSLLDIR%\include;%INCLUDE%
SET LIB=%OPENSLLDIR%\lib;%LIB%

REM ********** 3rd party build tools binaries: ruby, perl, python ********** 
SET PATH=C:\Ruby22-x64\bin;C:\Perl64\bin;C:\Python27;%PATH%

REM ********** Set up qt source env **********
SET _ROOT=E:\qt-everywhere-opensource-src-5.7.0
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 QMAKESPEC=win32-msvc2015
SET _ROOT=

REM Generate makefile
configure.bat -confirm-license -opensource -platform win32-msvc2015 -debug-and-release -static -target xp -prefix D:\Qt\Qt5.7.0-static-win32-vs2015-xp -qt-sql-sqlite -qt-sql-odbc -plugin-sql-sqlite -plugin-sql-odbc -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -qt-freetype -openssl-linked OPENSSL_LIBS="-lssleay32 -llibeay32 -lgdi32 -luser32" -no-qml-debug -no-angle -nomake tests -nomake examples -mp

 

其他问题:

  1. 我第一次尝试使用 openssl 1.1 配合qt进行编译,但报了一个错。猜测可能是因为openssl 1.1版本去除了sslv2支持。所以又改为使用openssl 1.0.2了。
  2. OPENSSL_LIBS需要引用 gdi32。因为openssl中用到了其中的函数(我没有实际测试是否需要user32,编译太慢,以防万一也加上了)。