Ășlfurinn

Building Qt on Windows (revisited)

Latest revision: 2014-01-12

Qt is a great library, but the only officially provided Windows/Mingw package is a shared 32-bit release build, which obviously doesn’t really cover all development needs. If you want to build other variants, you’re on your own. This post documents how I do it. For the sake of completeness, I’ll show how to build the required libraries as well.

Prerequisites

  • mingw – I get both 32 and 64 versions from mingw64. Recommended builds (I’m using 4.8.2, win32 threads, non-SJLJ exceptions for both platforms):
  • msys
  • ruby
  • python
  • perl – I like ActiveState, but whatever works for you.
  • zlib
  • openssl
  • ICU – see below
  • Qt source – obviously.

Environment

Prepend your mingw/bin to the PATH.

I also keep a pristine source tree of every source component and make a copy for every build variant. Mind the disk space with Qt though.

Building

All instructions are applicable to both 32-bit and 64-bit builds, unless otherwise noted.

zlib

Open an msys session, cd to your source copy. Run:

export ZLIB_ROOT=`pwd`
export INCLUDE_PATH=include
export LIBRARY_PATH=lib
export BINARY_PATH=bin
make -f win32/Makefile.gcc
make install -f win32/Makefile.gcc

openssl

Still in msys, cd to the openssl tree. Run:

export OPENSSL_ROOT=`pwd`

# 32-bit:
perl Configure --prefix=`pwd` \
    --with-zlib-lib=$ZLIB_ROOT/lib \
    --with-zlib-include=$ZLIB_ROOT/include \
    zlib shared mingw
# 64-bit:
perl Configure --prefix=`pwd` \
    --with-zlib-lib=$ZLIB_ROOT/lib \
    --with-zlib-include=$ZLIB_ROOT/include \
    zlib shared mingw64

make
make test       # this takes way longer than the build itself
make install

Say no-shared instead of shared if you want a static build.

ICU

full build instructions

qt 5.2

Qt builds cleaner in cmd.

After configure is done, review the detected configuration. You want to see confirmed support for ICU, linked OpenSSL and system Zlib.

The full build takes several hours.

set INCLUDE=%ZLIB_ROOT%\include;%OPENSSL_ROOT%\include;%ICU_ROOT%\dist\include
set LIB=%ZLIB_ROOT%\lib;%OPENSSL_ROOT%\lib;%ICU_ROOT%\dist\lib
set PATH=%ICU_ROOT%\dist\lib;%PATH%
configure -prefix %CD%\dist -debug-and-release -opensource -shared -nomake examples -opengl desktop -openssl-linked OPENSSL_LIBS="-lssl -lcrypto"
mingw32-make -j4
mingw32-make install

Say -static instead of -shared if you want a static build. You may want to apply the flto patch if you want to use link-time optimization. While you’re editing qmake.conf, in addition to these fixes, add -lgdi32 to the list of QtCore and QtNetwork dependencies because the static openssl libs will drag it in, and -O2 -m32 -msse -msse2 -mssse3 to LDFLAGS or you’ll get cryptic errors from LTO.

configure has to be run twice to detect ICU in static mode. A few tools will fail to build, this appears to be caused by LTO bugs in mingw. I’ll see if I can find a workaround.