Here's is a small guide about how to use Qt 4.7.3 with Visual Studio 2010 and static linking.
With this approach you can generate a single exe without dependencies to any Qt dlls or msvcr100.dll
Prerequisites:
- Install Visual Studio 2010
- Install Visual Studio 2010 SP1
- Download Qt Source: http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.3.zip
- Download and install the Qt VS 2010 Plugin http://qt.nokia.com/downloads/visual-studio-add-in
- Download and install this patch for VS2010: http://support.microsoft.com/kb/2280741
Now proceed with this simple steps:
1) Extract the Qt source code to C:\qt\4.7.3.static
2) Add the folder above to your environment variables
QTDIR = C:\qt\4.7.3.static
Also append the qt location to your path variable
3) Change the target configuration.
Edit the file ${QTDIR}\mkspecs\win32-msvc2010\qmake.conf and replace
QMAKE_CFLAGS_RELEASE = -O2 -MD QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi QMAKE_CFLAGS_DEBUG = -Zi -MDd
with
QMAKE_CFLAGS_RELEASE = -O2 -MT QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi QMAKE_CFLAGS_DEBUG = -Zi -MTd
and save it. This ensures that Qt itsself will not depend on msvcr100.dll
4) Open the Visual Studio command prompt (be sure to use x86 or x64 depending on your target) and navigate to QTDIR
5) Run configure
configure -static -debug-and-release -opensource -no-qt3support -qt-sql-sqlite -phonon -phonon-backend -platform win32-msvc2010
Change the flags to reflect your needs, just be sure to retain the static and platform flags.
Accept the license with 'y' and wait while Qt is getting configured.
6) Run nmake to start compiling
nmake
If you already installed Qt before you may skip the compilation of the examples and qt tools
nmake sub-src
This will take a while.
7) Start VS2010
Go to Qt-> Qt-Options add the just compiled Qt version found within the QTDIR folder.
8.) Done.
Now you can create a new Qt project:
- New > Project > Qt Application
- Finish the wizard
- Change the project settings: set the c++ code generation run time library option to /MT or /MTd
- If you're using any Qt Plugins, be sure to add the required lib files to the linker options and to add Q_IMPORT_PLUGIN directives to your source (see http://doc.qt.nokia.com/latest/plugins-howto.html#static-plugins)
Enjoy.