Build Qt Statically

This article is a list of steps to build Qt statically on Windows so that you can build your applications as a single self-contained binary. The environment for building is MINGW 32

Downloads

Before you start you need to download the following files. This link is a good place to start searching for the files: Qt official releases. At the moment of writing the latest version of Qt was 5.14:

  1. Qt installation that includes MINGW compilers. File name: qt-opensource-windows-x86-5.14.2.exe
  2. Qt source files we are going to compile statically. File name: qt-everywhere-src-5.14.2.zip

Prepare build environment

  • First execute the installer (download 1). We will use c:\qt as our installation directory. The target direction will be C:\qt\Qt5.14.2. Select Qt tools and MINGW 32 toolchain.

  • Unzip the source files to C:\qt\src. The root of the source tree will be C:\qt\src\qt-everywhere-src-5.14.2\

Environment variables

Before we can build Qt, we need to create a cmd file that will setup all required variables. The file name I use is env.cmd with the following content:

set PATH=C:\qt\Qt5.14.2\Tools\mingw730_32\bin;C:\qt\Qt5.14.2\Tools\mingw730_32\opt\bin;C:\Windows\System32;C:\Windows
set LANG="en"
set QT_INSTALL_PREFIX=c:\qt\Static\5.14.2

In cmd call the new file to set our variables:

env.cmd

Configure and build

In cmd go to the source directory and run configure:

cd C:\qt\src\qt-everywhere-src-5.14.2\
configure.bat -static -debug-and-release -platform win32-g++ -prefix C:\qt\Static\5.14.2 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -no-openssl -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests

This seems to be the settings working for minimal Qt applications. The configure command will take some time to run. Depending on your hardware it can take several minutes.

Check your %ERRORLEVEL% variable. It should be 0 after configure.bat finishes. If it is successful, we can start the build:

mingw32-make -k -j 4

The building will take a lot of time. Best to leave it overnight. -k instructs make to continue building if there are errors. The next morning run the install command:

mingw32-make install

Done

After the steps above you will find all binaries for building your Qt application statically under c:\qt\Static\5.14.2.

links

social