Building Qt on Windows (VC++ 2010)

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

Creating a Qt programming environment on Windows (using the VC++ 2010 compiler)


Download the latest Qt source code:

Visual C++ 2010 SP1 (Express):

DirectX SDK:

For 64-bit development, additionally install the Windows SDK 7.1...

... and this hot-fix for a known x64 recode optimization issue (in short: using optimization option /O2 leads to a crash in all software built for x64):

Prepare the environment

For 32-bit, open the Visual Studio 2010 Command Prompt:

 Setting environment for using Microsoft Visual Studio 2010 x86 tools.
 C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>echo %PATH%
 C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN;C:\Program Files
  (x86)\Microsoft Visual Studio 10.0\Common7\Tools;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Windows\Microsoft.NET\Framework\v3.5;C:\P
 rogram Files (x86)\Microsoft Visual Studio 10.0\VC\VCPackages;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools;C:\Pro
 gram Files (x86)\Microsoft SDKs\Windows\v7.0A\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerSh
 ell\v1.0\;c:\Qt\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft Windows Performance Toolkit\

For 64-bit, open the Windows SDK 7.1 Command Prompt:

 Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v7.1
 Targeting Windows 7 x64 Debug
 C:\Program Files\Microsoft SDKs\Windows\v7.1>echo %PATH%
 indows\Microsoft.NET\Framework\v3.5;;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE;C:\Program Files (x86)\Microsoft Visual
 Studio 10.0\Common7\Tools;;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\amd64;C:\Program Files (x86)\Microsoft Visual Studio 1
 0.0\VC\Bin\VCPackages;;C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\x64;C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin
 \x64;C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin;;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPo
 werShell\v1.0\;c:\Qt\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft Windows Performance Toolkit\

DirectX support

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

 d:\Qt4>c:\DXSDK\Utilities\bin\dx_setenv.cmd x86
 Dx x86 target environment is now enabled.
 Dx x64 host environment is now enabled.


 d:\Qt4-64>c:\DXSDK\Utilities\bin\dx_setenv.cmd AMD64
 Dx x64 target environment is now enabled.
 Dx x64 host environment 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 Qt

 d:\Qt4>configure.exe -fast -opensource -confirm-license -release -platform win32-msvc2010 -phonon -qt-style-windowsxp -qt-style-windowsvista
 Qt is now configured for building. Just run nmake.
 To reconfigure, run nmake confclean and configure.


  • 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!
  • You should also explicitly set QMAKESPEC=win32-msvc2010 when running qmake for your projects later (or use qmake -tp vc -spec win32-msvc2010).

Building Qt

Just run nmake (as the configuration step suggests when it's finished):


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.

Trouble shooting

x64 builds: TRACKER error TRK0005/TRK0002 spawning RC.EXE ("handle is invalid")

Tracker.exe appears to have an issue calling the right version of RC.EXE (or ResGen.exe) for an x64 build environment, which results in a weird error when building any of your Qt projects that embed resources.

The quick fix which helped in my case was to replace the x86 version (which apparently gets called) with the x64 one:

 c:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools>copy Tracker.exe Tracker.exe.orig
 c:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools>copy x64\Tracker.exe Tracker.exe

See also

Windows specific official installation instructions: