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:
- Microsoft Visual Studio 2008
- The Qt sources (4.5.3 at the time of this writing)
- Qt Visual Studio Addin
What you do (assuming VS2008 is already installed):
- Unpack the Qt sources. I used C:\Qt\4.5.3-win32-msvc2008 as target (%QTDIR%)
- 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
- Next, open a Visual Studio 2008 Command Prompt (under the Start menu), go to %QTDIR% and run
configure.exewith at least-staticas option. I used the following (minimal build): - Once configured, start the build:
nmake sub-src
- Install the Qt Visual Studio Addin
- 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
- Optionally you can test your installation by creating a new Qt Project, compiling it and running it.
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
Easy enough?! Happy Qt’ing!
UPDATE 15/10/2009: This also works with MS Visual Studio C++ Express Edition!