Building Qt on Windows (MinGW)

From BATCOM-IT Services Wiki
Jump to: navigation, search

Creating a Qt programming environment on Windows (using the MinGW compiler)


Download the latest Qt source code:

The MinGW compiler -- I'd recommend installing a ready-made binary distribution like the latest MAME dev-tools:

DirectX / Windows SDK (optional):

Check/set the %PATH% environment variable

Open a command prompt (cmd.exe) and check/set your environment:

c:\Qt>set PATH=<path-to-mingw-w32-or-w64>\bin;%PATH%

For example:

c:\Qt>set PATH=c:\mingw64-w64\bin;%PATH%

Tweaking Qt

Qt 4 only

In order to avoid library dependencies with libstdc++-6.dll and libgcc_s_sjlj-1.dll, add the following line to mkspecs\win32-g++-4.6\qmake.conf:

QMAKE_LFLAGS = -static-libgcc -static-libstdc++

Also change line 30 of qmake\Makefile.win32-g++ from

LFLAGS = -static-libgcc -s


LFLAGS = -static-libgcc -static-libstdc++ -s

DirectX support (optional)

To enable DirectX support in Qt, you'll need to setup the DirectX SDK's environment variables before the Qt configuration step:

c:\Qt>\DXSDK\Utilities\bin\dx_setenv.cmd x86
Dx x86 target enviroment is now enabled.
Dx x86 host enviroment is now enabled.


c:\Qt-64>\DXSDK\Utilities\bin\dx_setenv.cmd AMD64
Dx x64 target enviroment is now enabled.
Dx x64 host enviroment is now enabled.

Note that it's important to pass the right target architecture (x86 for 32-bit, AMD64 for 64-bit) when calling dx_setenv.cmd! The default is x86.

Configuring and building Qt

Qt 4 example

c:\Qt>configure.exe -fast -opensource -confirm-license -platform win32-g++-4.6 -release -phonon -qt-style-windowsxp -qt-style-windowsvista

c:\Qt>mingw32-make [-j #CPUs]


  • To disable building of examples and demos, edit the file and comment the two lines containing SUBDIRS += examples and SUBDIRS += demos before running configure.exe!

Qt 5 example

c:\Qt5>configure.bat -opensource -confirm-license -nomake examples -qt-style-windowsxp -qt-style-windowsvista -opengl desktop -no-angle

c:\Qt5>mingw32-make [-j #CPUs]


  • The examples are disabled via the configure.bat command line. If you want to build them, omit -nomake examples.
  • Due to other (known) reasons I can't install the latest Windows 8.1 SDK which is required for ANGLE support, so omit -opengl desktop -no-angle if you have that installed.

Installation and usage

You don't need to explicitly install Qt on Windows. The library can be used right away and from the place (directory) it has been built in. You could, however, freely rename and/or move the (complete) directory. In this case you will have to setup qmake (see qmake -query / -set and qt.conf) and probably also set QT_PLUGIN_PATH.

See also

Windows specific official installation instructions: