Building a static version of Qt libraries

I. Building a static version of OpenSSL libraries (libcrypto.lib and libssl.lib)

Sources:

Actions:

1. Open the Perl shell (command line) and go to OpenSSL source directory:

cd c:\OpenSSL\openssl-1.1.1q

2. Create makefile for static release libraries in target d:\OpenSSL\Release directory:

perl Configure VC-WIN64A no-shared no-stdio no-sock --prefix=d:\OpenSSL\Release\ --openssldir=d:\OpenSSL\Release\

3. Check makefile for LIB_CFLAGS=/MT option.

4. Run Visual Studio 2019 x64 Native Tools Command and go to OpenSSL source directory:

cd c:\OpenSSL\openssl-1.1.1q

Then run the following commands consequently:

nmake
nmake install

5. Check d:\OpenSSL\Release\lib\ directory for libcrypto.lib and libssl.lib files.


II. Building a static version of Qt libraries directly linked to static OpenSSL libraries

Sources:

  • Jom is a clone of nmake to support the execution of multiple independent commands in parallel. (https://download.qt.io/official_releases/jom/jom.zip). Extract it to d:\Qt\JOM_3_1_1 for example.
  • Python (https://www.python.org/downloads/release/python-2716). Install it to d:\Python27\.
  • qt-everywhere-src-5.15.2.zip source codes (https://download.qt.io/archive/qt/5.15/5.15.2/single). Extract it to c:\Qt-5\ for example

    Go to C:\Qt-5\qtbase\mkspecs\common and change msvc-desktop.conf like this (change all MD to MT to remove dependency on msvc dlls) initial values:

    QMAKE_CFLAGS_RELEASE = -O2 -MD
    QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
    QMAKE_CFLAGS_DEBUG = -Zi -MDd


    should be changed to:

    QMAKE_CFLAGS_RELEASE = -O2 -MT
    QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi
    QMAKE_CFLAGS_DEBUG = -Zi -MTd


  • libcrypto.lib and libssl.lib OpenSSL static libraries, for example in d:\OpenSSL\Release\lib directory. The include files are in d:\OpenSSL\Release\include directory.
  • AdvAPI32.Lib, Crypt32.Lib, Gdi32.Lib, User32.Lib system files in d:\OpenSSL\Release\lib directory. Copy from any Windows Kits, for example c:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x64. This is required to create the correct static OpenSSL configuration (-openssl-linked).
  • Visual Studio 2019 x64 compiler.

Actions:

1. Run Visual Studio 2019 x64 Native Tools Command and go to Qt source directory:

cd c:\Qt-5

2. Add jom and Python directories to PATH:

SET PATH=d:\Qt\JOM_3_1_1;d:\Python27\;%PATH%

3. Create makefile for static Qt libraries with static OpenSSL libraries for d:\Qt\Qt5.15.2\msvc2019_static_ssl_64 target directory:

configure -static -debug-and-release -no-pch -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -plugin-sql-sqlite -opengl desktop -prefix d:\Qt\Qt5.15.2\msvc2019_static_ssl_64 -platform win32-msvc2019 -nomake examples -nomake tests -skip qtdoc -skip qtwebengine -opensource -confirm-license -make libs -nomake examples -nomake tests -openssl-linked -I "d:\OpenSSL\Release\include" -L "d:\OpenSSL\Release\lib" OPENSSL_LIBS="-llibcrypto -llibssl -lgdi32 -ladvapi32 -lcrypt32 -luser32"

Check c:\Qt-5\config.summary report for:

OpenSSL ................................ yes
Qt directly linked to OpenSSL ........ yes
OpenSSL 1.1 ............................ yes


4. Then run the following commands consequently:

jom
jom install

5. Add libcrypto.lib and libssl.lib along with Qt libraries to application project.