From Qt Wiki
Revision as of 07:14, 10 February 2015 by Maintenance script (talk | contribs)
Jump to: navigation, search

I suggest to merge the (important) content from here with the article on MinGW. Please feel free to help out.

MinGW 64 bit

This is about MinGW-w64, MinGW, MSYS, MSYS2 and Qt 5.

Executive Summary

We recommend a MinGW-w64 based distribution with a recent gcc. Starting with Qt 5.0.1 there are also binary installers that ship a Mingw-w64 based toolchain + pre-built Qt libraries. The MinGW-builds repo includes MinGW-w64 toolchains.

Recommended package for 32 bit (also tested in CI system + used by installer for 5.1):

Recommended package for 64 bit:

Community member George Edison has cross-compiled Qt 5.0.1 for Windows using the Mingw-w64 compilers and is hosting the archives here:


The MinGW from http://www.mingw.org/ does only support gcc 32 bit (host and target). The independent minGW-w64 project provides support for 64 bit, and also supports a much larger part of the Windows API. The MinGW-w64 project however does not provide official binary builds: These can be grabbed either from the personal build directories of the developers (the most popular being rubenvb), or from associated but independent projects like tdm-gcc or mingw-builds or msys2.

RubenVB personal builds

“RubenVB personal builds”: For 32-bit Windows target [sourceforge.net] targetting Win32/Personal Builds/rubenvb/ and for 64-bit Windows target [sourceforge.net] targetting Win64/Personal Builds/rubenvb/ :
Features different packages with cygwin, win32, win64, linux as host. Target is either win32 or win64. Packages are built with every GCC release, experimental and prerelease packages are built on request.


“MinGW-builds”: http://sourceforge.net/projects/mingwbuilds/ : a binary package by developer: niXman, lexx83 (Alexpux). Provides both packages with a 32-bit and a 64-bit compiler (Windows host), that can also cross-compile to 32-bit or 64-bit. Packages are available with both “posix” and “win32” threading libraries, for 32 bit also with sjlj or dwarf exception variants. See also MSYS2.


“MSYS2”: http://sourceforge.net/projects/msys2/ : MSYS2 (Minimal SYStem 2) is an independent rewrite of MSYS, a (command-line) shell for development usage, and based on modern Cygwin (POSIX compatibility layer) and MinGW-w64 (from “MinGW-builds”), with the aim of better interoperability with native Windows software. It includes: MSYS2-shell and MinGW-w64 Win32 shell & MinGW-w64 Win64 shell. It supports & can work with both 32bit & 64bit multiple toolchains & targets, (for 64bit a 64bit operating system is needed). MSYS2 is a successor of MSYS and MinGW-builds. MSYS2-shell uses “pacman” for downloading packages, and these are GPG signed & verified. Packages are by developer: lexx83 (Alexpux), mingwandroid, niXman. MSYS2 is a complete opensource development environment/shell solution/system. It can obtain related all toolchains & packages from “MinGW-builds” and MSYS2 repo, (and it also obtains related all dependency packages), for compiling/building other software. It can also obtain various tools & language support & compilers, like: perl, python, ruby, openssl, etc. A user has these options to choose from : by using MSYS2-shell & MinGW-w64 Win64 shell, (option-A), either download Qt or QtCreator source from MSYS2 repo and compile/build, or (option-B), a user can get official Qt source or QtCreator source, and then compile/build using mingw-w64 toolchains obtained/available via MSYS2, from the windows Cmd-shell, or (option-C), a user can download pre-built binary files of Qt & QtCreator (dynamic/shared built edition and/or static built edition) inside MSYS2 and run+use them instantly without compiling.

Exception handling: SJLJ, DWARF, and SEH

Some packages like MinGW-builds and TDM-GCC let you choose which exception implementation you want to use. You must ensure you use the same compiler used to build the Qt you use in order to avoid linker errors. If you choose to change the exception handling mechanism, you will need to rebuild all code, mostly because the libgcc shared library name is different between the exception handling settings.

SJLJ (setjmp/longjmp):

  • available for 32 bit and 64 bit
  • not “zero-cost”: even if an exception isn’t thrown, it incurs a minor performance penalty (~15% in exception heavy code) but sometimes the penalty can be more significant: https://bugreports.qt.io/browse/QTBUG-29653
  • allows exceptions to traverse through e.g. windows callbacks

DWARF (DW2, dwarf-2)

  • available for 32 bit only
  • no permanent runtime overhead
  • needs whole call stack to be dwarf-enabled, which means exceptions cannot be thrown over e.g. Windows system DLLs.

SEH (zero overhead exception)

  • will be available for 64-bit GCC 4.8.
  • rubenvb release is available [sourceforge.net] targetting Win64/Personal Builds/rubenvb/gcc-4.8-release/x86_64-w64-mingw32-gcc-4.8.0-win64_rubenvb.7z/download
  • MinGW-builds release is available [sourceforge.net]

From TDM-GCC readme:

GCC currently supports two methods of stack frame unwinding: Dwarf-2 (DW2) or
SJLJ (setjmp/longjmp). Until recently, only SJLJ has been available for the
Windows platform. This affects you, the end user, primarily in programs that
throw and catch exceptions. Programs which utilize the DW2 unwind method
generally execute more quickly than programs which utilize the SJLJ method,
because the DW2 method incurs no runtime overhead until an exception is thrown.
However, the DW2 method does incur a size penalty on code that must handle
exceptions, and more importantly the DW2 method cannot yet unwind (pass
exceptions) through “foreign” stack frames: stack frames compiled by another
non-DW2-enabled compiler, such as OS DLLs in a Windows callback.

This means that you should in general choose the SJLJ version of the TDM-GCC
builds unless you know you need faster exception-aware programs and can be
certain you will never throw an exception through a foreign stack area.

As distributed, the SJLJ and DW2 packages of TDM-GCC can coexist peacefully
extracted to the same directory (i.e. any files in common are for all intents
and purposes identical), because the driver executables (the ones in the “bin”
directory) are suffixed with “-dw2” for the DW2 build, and the libraries and
other executables hide in another “-dw2” directory in “lib(exec)/gcc/mingw32”.
This allows you to use the same single addition to your PATH, and use DW2
exceptions only when you need them by calling “gcc-dw2”, etc. If you truly want
DW2 exceptions as the default when calling “gcc” (from Makefiles or configury
systems, for example), you can rename or copy the suffixed executables to their
original names.”

DW2 Issues

  • If a library that uses DW2 exception handling (e.g. libgcc_s_dw2-1.dll) is loaded using LoadLibrary and FreeLibrary is not called, the program will crash. See http://comments.gmane.org/gmane.comp.gnu.mingw.user/41724
  • Calling FreeLibrary to unload a dll that links to both dynamic libgcc_s_dw2 and a library that links to static libgcc_s_dw2 results in a crash

GCC Threading model (posix vs win32)

Mingw-Builds (and the experimental rubenvb packages) also let you choose between the threading model internally used by (lib)gcc:

  • posix (built upon MinGW-w64’s winpthreads)
    • “an implementation of POSIX threads for win32 is also available under the experimental directory. Its main goal is to support C++11 standard threading, which supports only using POSIX threads at the moment.” http://mingw-w64.sourceforge.net/
    • enables C++11 library features contained in the headers <thread>, <mutex>, and <future>.
    • Performance degradation in specific scenarios. C++11 functionality is significantly slower than native Win32 implementation or even MSVS2012’s implementation.
  • win32
    • uses native Win32 threading functions.
    • no C++11 <thread>, <mutex>, or <future>
    • best performance

More reading: http://sourceforge.net/mailarchive/message.php?msg_id=28014658

Criteria for original decision on toolchain

Following criteria for selecting the mingw package have been brought up on the mailing list . The comments about mingw-builds, rubenvb might not be up to date any more.

  • Ease of installation
    • rubenvb: different packages (host x target etc) can be confusing. no additional configuration needed when not cross-compiling.
    • mingw-builds: 32 bit binaries do not have prefix, but requires additions to configure / mkspecs (to switch to 64 bit target)
  • Stability/Quality
    • mingw-builds: no issues in latest packages
    • rubenvb: no issues in latest packages
  • most recent compilers (GCC 4.7 preferably, GCC 4.6 if not)
    • mingw-builds: GCC 4.7.2 (and GCC 4.8 prerelease in testing [sourceforge.net])
    • rubenvb: GCC 4.7.2 (and GCC 4.8 prerelease in unstable) and a 32-bit Clang 3.2 [sourceforge.net] targetting Win32/Personal Builds/rubenvb/clang-3.2-release/
  • working GDB and tested with Creator (with required Python support)
    • mingw-builds: 7.5.1
    • rubenvb: 7.5
  • large file support (aka _FILE_OFFSET_BITS=64)
    • mingw-builds: yes (_FILE_OFFSET_BITS in headers, also e.g. lseek64 symbol defined)
    • rubenvb: yes (_FILE_OFFSET_BITS in headers, also e.g. lseek64 symbol defined)
  • threading
    • mingw-builds: gcc -v says ‘posix’ or ‘win32’ depending on which build you download
    • rubenvb: gcc -v says ‘win32’ . std::thread support in experimental package [sourceforge.net] targetting Win64/Personal Builds/rubenvb/gcc-4.7-experimental-stdthread//Personal Builds/rubenvb/gcc-4.7-experimental-stdthread/
  • zero-overhead exceptions (no SJLJ exceptions)
    • rubenvb: 32-bit GCC dw2 builds provided, and GCC 4.8 prerelease is 64-bit seh.
    • mingw-builds: 32-bit GCC dw2 builds provided, and GCC 4.8 prerelease is 64-bit seh.
  • standard win32 headers, if possible using the Platform SDK headers
    • rubenvb: Win32 API, DirectX (from WINE project), and DDK (from ReactOS project)
    • mingw-builds: Win32 API, DirectX (from WINE project) and DDK (from ReactOS project)
  • large set of included libraries
    • rubenvb: none, only Win32 and GCC libraries provided.
    • mingw-builds: libcharset, libiconv, libksguid, libportabledeviceguids, libsensorsapi, libwindowscodecs, libwinhttp
  • 32 and 64-bit in one package
    • rubenv: 64 bit or 32 bit are seperate packages
    • mingw-builds: both 32 bit and 64 bit host, 32 bit and 64 bit target
  • make with -j support
    • rubenvb: -j seems to work
    • mingw-builds: -j seems to work
    • NOTE: Qt’s own “jom” tool can be used to build Qt and CMake “MinGW Makefiles” with much better performance than mingw32-make

MinGW-builds (with OpenSSL, ICU and QtWebKit)


  • The “MinGW-builds” uses toolchains from “MinGW-w64” project.
  • We compile our own OpenSSL and ICU binaries instead of using prebuilt binaries to avoid additional dependencies on the Visual C++ 2008/2010 runtimes


  • Either follow Option-A, or follow Option-B. Don’t follow both options at same time (unless you know what you are doing).

Option-A Prerequisites

Option-B Prerequisites

  • Microsoft DirectX SDK June 2010 (http://www.microsoft.com/en-us/download/details.aspx?id=6812 [microsoft.com]) – needed if you want ANGLE
  • MSYS2 (https://msys2.github.io/ [msys2.github.io]). MSYS2-shell can load all other components & dependencies & tools, other than DirectX, shown in above Option-A, see msys2 related option below. Install MSYS2 in C:\ drive in “msys2” folder.
  • Git checkout or extracted source archive of Qt 5 at C:\Qt\qt5 or /c/Qt/qt5

Initial Setup

Either use option-A, or, use option-B. Don’t use both options at same time (unless you know what you are doing).

  • Initial stage option-A: Obtain & Extract MinGW-builds GCC 4.8.2 64-bit to this folder: C:\Qt\mingw64-4.8.2
  • Initial stage option-B: Obtain MSYS2, install in C:\msys2, then prepare MSYS2 for Qt related build development environment: Run MSYS2 shell (C:\msys2\msys2_shell.bat). First update msys2 core components (if you have not done it already):
    You must exit out from MSYS2-shell, restart MSYS2-shell, then run below command, to complete rest of other components update:
    Exit out again from MSYS2-shell, restart MSYS2-shell, now you are ready to use this shell, prepare it for building/compiling environment : run below command to load MinGW-w64 SEH (64bit/x86_64) and Dwarf-2 (32bit/i686) posix toolchains, dependencies & other required tools from MSYS2 REPO:

Building OpenSSL

See also Compiling OpenSSL with MinGW

  • Download latest+stable edition of OpenSSL [openssl.org] from https://www.openssl.org/source/openssl-1.0.1e.tar.gz to C:\Qt\qt5_deps\openssl-1.0.1e.tar.gz
  • Start a MSYS (or MSYS2) shell command prompt
    If you are using MSYS, only then run below command. If you are using MSYS2, then do not run below command.
    If you are using MSYS2, only then run below command. If you are using MSYS, then do not run below command.
    Run these commands (if you are using either MSYS or MSYS2):

Building ICU (Unicode support)

See also Compiling ICU with MinGW

  • Download ICU from http://download.icu-project.org/files/icu4c/52.1/icu4c-52_1-src.zip to C:\Qt\qt5_deps\icu4c-52_1-src.zip
  • Start a MSYS (or MSYS2) shell command prompt
    If you are using MSYS, only then run below command. If you are using MSYS2, then do not run below command.
    If you are using MSYS2, only then run below command. If you are using MSYS, then do not run below command.
    Run these commands (if you are using either MSYS or MSYS2):

Building Qt

  • Note: If you are using the Qt 5 source .tar.gz, you need to do the following for configure.exe to build properly:
    • Start a Windows command prompt (Cmd-shell)
  • Start a Windows command prompt (Cmd-shell), and run/execute below commands:
    If you have downloaded perl, ruby, python separately from their official websites & installed in separate folders, then adjust & execute/run below command:
    If you have installed/loaded perl, ruby, python inside MSYS2, using “pacman” command, then adjust & execute/run below command:
    Run below commands, (if you have installed perl, ruby, python from their official sites, or, if you have installed perl, ruby, python via pacman inside MSYS2-shell):
    Note: If you want to build using ANGLE instead of desktop OpenGL, remove “-opengl desktop” from configure.




  • This is the set of scripts to build Qt : either with “MinGW-builds” based toolchains under MSYS, or, to build Qt : with MSYS2 repo (also based on “MinGW-builds”) based toolchains under MSYS2.
  • If you want to use pre-compiled or pre-built Qt & QtCreator binary files, then follow one of these:
    • The “MinGW-builds” based Qt binary builds (pre-built) can be downloaded from https://sourceforge.net/projects/mingwbuilds/files/external-binary-packages/Qt-Builds/ [sourceforge.net] Note: it is not updated after Qt v5.2.1 (as of today: Feb 2nd 2015).
    • The “MSYS2” based Qt binary builds (pre-built) can be downloaded from https://github.com/Alexpux/MINGW-packages [github.com] (MSYS2 REPO) or, use below simple command inside MSYS2-shell to get+install Qt & QtCreator binary pre-builts, for developing & releasing opensource or closedsource projects:
      If you also need+want static binary builds, for compiling & releasing opensource projects, then use below command:


To build Qt, these are required:

Initial Setup

  • Either use MSYS, or MSYS2. Do not use both, (unless you know what you are doing).
    • If you are going to use MSYS: extract or install MSYS into C:\QtSDK\MSYS directory
    • If you are going to use MSYS2: extract or install MSYS2 into C:\msys2 directory
  • Prepare MSYS or MSYS2 for development environment: pre-install build related required dependencies & components.
    • See inside MinGW-builds section (in above), on how you can prepare MSYS or MSYS2 for building/compiling.
  • Run MSYS (or MSYS2)
  • run git checkout scripts:

Building Qt

Now scripts provide building Qt-4.8.4, Qt-5.0.0, Qt-5.0.1, Qt-5.0.2, Qt5 from git with latest release of QtCreator, qbs(from git). Buildinq Qt is simple by run:
For example,
build 32-bit Qt-5.0.0 with QtCreator-2.7.0 and install them into C:/QtSDK/Qt32-5.0.0, Qt dependencies and prerequisites will be installed into C:/QtSDK/ported32.

For building Qt5 from git you need specify branch what you want to build. If you don’t specify branch then by default building stable branch.
This command download qt5 from git stable branch and try to build 32-bit version of Qt5.

Note: If you want to move Qt directory elsewhere than after moving you need to execute from QTDIR:

Other useful options are:

Notes: Do not use (or try to avoid using) different type of toolchains for building different sub-components for the same/main project, when targeted for same platform/OS. If you are using MinGW-w64 based toolchains from MSYS2\mingw32 or MSYS2\mingw64, then for all sub-components build and for main project build, use same MSYS2 toolchains. If you are using MinGW toolchain, then for all of your sub-components & main project build, use same MinGW toolchain. If you are using MinGW-w64 toolchains from “MinGW-builds”, then for all sub-components and for main project build, use same MinGW-builds toolchains.

See also

How to build a static Qt for Windows MinGW
Building Qt 5 from Git
Buildint static Qt on Windows [qtcentre.org]
Building static applications [qtcentre.org]
How to build a static Qt version for Windows with GCC [developer.qt.nokia.com]
Setting up Qt on Ubuntu in VirtualBox
Building Qt Package
Building Qt Creator from Git
Compiling ICU with MinGW
Compiling OpenSSL with MinGW
Using Shadow Builds – Windows CE [doc.qt.io]
http://msdn.microsoft.com/en-us/library/ms235591(v=VS.80).aspx : How to: Embed a Manifest Inside a C/C++ Application