Statically Linked Qt On Win32 Using MSVC

I have been trying to compile a statically linked version of Qt on Windows using MSVC for some time now but never found my way through until recently. There is a lot of information on the web about how to do this however I haven’t found one that actually worked for me (some information can be found on Trolltech’s website). So here’s yet another howto for using a static version of Qt with Visual Studio 2008!

What you need:

What you do (assuming VS2008 is already installed):

  1. Unpack the Qt sources. I used C:\Qt\4.5.3-win32-msvc2008 as target (%QTDIR%)
  2. If you have a multicore CPU you might want to speedup things by modifying %QTDIR%\mkspecs\win32-msvc2008\qmake.conf and adding those two lines (change 2 for the no. of CPUs you have):
    QMAKE_CXXFLAGS_RELEASE += -MP2
    QMAKE_CXXFLAGS_DEBUG += -MP2
  3. Next, open a Visual Studio 2008 Command Prompt (under the Start menu), go to %QTDIR% and run configure.exe with at least -static as option. I used the following (minimal build):
  4. configure.exe -debug-and-release -opensource -static -no-exceptions -no-accessibility -no-stl -no-qt3support -no-opengl -platform win32-msvc2008 -qt-zlib -qt-gif -qt-libpng -qt-libmng -qt-libtiff -qt-libjpeg -no-openssl -no-dbus -no-phonon -no-webkit -no-scripttools

  5. Once configured, start the build:
    nmake sub-src
  6. Install the Qt Visual Studio Addin
  7. In Visual Studio, under the Qt menu choose Qt Options. Under the Qt Versions tab click Add and type 4.5.3_win32-msvc2008 (or whatever you want) and fill in the path where you extracted the Qt sources
  8. Optionally you can test your installation by creating a new Qt Project, compiling it and running it.

Easy enough?! Happy Qt’ing!

UPDATE 15/10/2009: This also works with MS Visual Studio C++ Express Edition!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s