Qt 6.8.1 Static Compilation Guide for Windows 7

Last Modified: 15-01-2025

This guide focuses on a partial but working Qt 6.8.1 static compilation with MSVC on Windows 7 with the most common optional modules. Unfortunately, building complete static builds is currently broken right now.

Time to compile: around 1 hour on Intel Core i7-4770 @ 3.40GHz (4C/8T).

Required Software

Qt6

  • MSVC build tools 2019 or higher.
  • CMake 3.21 or higher.
  • Ninja 1.7.2 or higher.
  • Python >3.7 and <3.10. 3.8 is highly recommended.

    If you have other Python installations higher than 3.9, move them to a seperate directory temporarily and hide it.

  • Git.
  • OpenSSL 3.0.15 or higher. Required to link statically to OpenSSL libs; no longer require libcrypto-3-x64.dll and libssl-3-x64.dll for QtWebChannel.

Required Files

Steps

  1. Create directory structure. For the purposes of this guide, we choose a Qt home directory of C:\Qt.
  2. Extract sources

    • Qt 6.8.1 sources to C:\Qt\6.8.1\src_min.
    • Out of all directories included with the Qt6 source code, we only require some of the optional modules. Ensure that only the below directories are present in your source directory.
      1
      2
      3
      4
      5
      6
      7
      8
      qtbase
      qtdeclarative
      qtimageformats
      qtsvg
      qttools
      qttranslations
      cmake
      qt5compat
      
  3. Apply patches

    • For Qt 6.8.1, simply override all files in C:\Qt\6.8.1\src with the ones included in the Windows 7 GitHub repoistory.
  4. Configure Qt 6.8.1 building prerequisites

    • To avoid OpenSSL mixups, we need to use the static multithreaded OpenSSL libs included with the full OpenSSL toolchain.
      • To do this, select a new directory for OpenSSL static libs such as C:\Libs\openssl-3.4.0-w64
      • Copy the following files from your OpenSSL toolchain directory (e.g. C:\Program Files\OpenSSL) to the new directory
        • libcrypto_static.lib and libssl_static.lib from lib\VC\x64\MT to C:\Libs\openssl-3.4.0-w64\lib. Rename them to libcrypto.lib and libssl.lib, respectively.
        • include to C:\Libs\openssl-3.4.0-w64\ (the whole directory).
  5. Build Qt 6.8.1 sources

    • Create build directory C:\Qt\6.8.1\build_static_min.
    • Select installation directory C:\Qt\6.8.1\msvc2019_64_static_min.
    • Verify static OpenSSL directory C:\Libs\openssl-3.4.0-w64.
    • Open x64 Native Tools Command Prompt for VS 2019 and execute the following commands line-by-line:
      cd C:\Qt\6.8.1\build_static_min
      C:\Qt\6.8.1\src_min\configure.bat -prefix C:\Qt\6.8.1\msvc2019_64_static_min -release -static -static-runtime -accessibility -no-icu -no-sql-sqlite -no-qml-debug -nomake examples -nomake tests -platform win32-msvc -openssl-linked -- -DOPENSSL_ROOT_DIR="C:\Libs\openssl-3.4.0-w64" -DOPENSSL_INCLUDE_DIR="C:\Libs\openssl-3.4.0-w64\include" -DOPENSSL_USE_STATIC_LIBS=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -Wno-dev
      
    • Wait for configuration to complete. No errors or warnings should be reported.
    • Build Qt 6.8.1 with the following command. This should take around an hour.
      cmake --build . --parallel
      
    • Once building is complete, install Qt 6.8.1 to the chosen installation directory using the following command.
      cmake --install .
      
    • To verify successful building, open designer.exe in C:\Qt\6.8.1\msvc2019_64_static_min\bin. The Qt Widgets Designer should open fine.
    • To verify static linking, Qt6Core.dll should not be present in C:\Qt\6.8.1\msvc2019_64_static_min\bin.

Appendix: Building Qt 6.8.1 for use alongside Boost

If the program you intend to link Qt statically against uses Boost as a library (e.g. qBittorrent) the program will not link properly due to mismatches in the coroutine ABI.

To fix this issue, maintain the same build steps as above, but replace the configuration command with the following:

C:\Qt\6.8.1\src_min\configure.bat -prefix C:\Qt\6.8.1\msvc2019_64_static_min_cr -release -static -static-runtime -accessibility -no-icu -no-sql-psql -no-sql-sqlite -no-qml-debug -nomake examples -nomake tests -platform win32-msvc -openssl-linked -- -DCMAKE_CXX_FLAGS="/await:strict"  -DOPENSSL_ROOT_DIR="C:\Libs\openssl-3.4.0-w64" -DOPENSSL_INCLUDE_DIR="C:\Libs\openssl-3.4.0-w64\include" -DOPENSSL_USE_STATIC_LIBS=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -Wno-dev 

This will compile Qt 6.8.1 with a coroutine ABI version compatible with Boost.

Edit

Pub: 15 Jan 2025 21:44 UTC

Views: 118