Compile Qt 4.5 for Visual Studio, using your multi-core processor

— richardwb on Thursday, June 25, 2009 @ 20:28

If you want to use Qt 4.5 with Visual Studio you'll need to compile it yourself. The instructions are simple, and fairly well documented on various blogs and websites. Essentially: (read steps 7 and on for multi-threading information)

[Edit: These steps still apply for Qt 4.6, but Qt 4.6 actually has prebuilt binaries/libraries for Visual Studio 2008 which I highly suggest looking at instead]

  1. This step is important. You will potentially save some time by deleting these mocinclude.tmp files:


    Deleting the first two mocinclude.tmp files will prevent a LNK2019 error from building Webkit, while deleting the last two (which are present in Qt 4.6) will prevent Error: Unknown interface from occurring while trying to build qscriptextensionplugin.h. If you're missing any of them don't fret, it's actually a good thing.

  2. Using a Visual Studio Command Prompt, navigate to your Qt folder (I'll use D:\Coding\Qt\2009.05 in this example).

  3. Go to the Qt folder inside there (e.g. D:\Coding\Qt\2009.05\qt). It's the one that contains configure.exe.

  4. Enter the following command, changing win32-msvc2008 to win32-msvc2005 if necessary.

    > configure -opensource -shared -ltcg -no-qt3support -platform win32-msvc2008
  5. What this does is fairly self explanatory. The -shared switch will make sure that Qt is configured for dynamic linking (even though that's usually the default option there's no guarantee). We need to specify the -ltcg switch to turn on Link Time Code Generation. LTCG is off by default since, in combination with a statically built Qt, it will make linking very slow for any projects that use Qt. However, if we configure Qt for dynamic linking this won't be an issue.

  6. You can add or remove switches as desired (try configure help) but I find most of the defaults suitable. Sure, you may not need OpenGL (or SQL or Phonon or...) support right now, but it's a separate module anyway and you're already compiling the rest of Qt.

  7. All you need to do now is run nmake...but wait.

  8. Do you have a dual-core or quad-core processor or can take advantage of multi-threaded compilation? Get the jom tool instead. There's some info about jom in this Qt Labs Blogs article. You can download the latest version of jom from ( should be just fine).

  9. Use jom by simply unzipping and running it in the same directory as configure (which is still the same as before, D:\Coding\Qt\2009.05\qt).

    > jom
  10. Happily build Qt much faster. For example, on my machine (a Core 2 Quad) it took an hour for the build to complete.

  11. Unless you really enjoy manually handling custom build steps, don't forget to get the Qt Visual Studio Add-In. After installing it make sure that it's aware of the location of your Qt installation (Qt->Qt Options) and then use File->New->Project... and select one of the Qt templates to get started.

comments powered by Disqus