Springe zum Inhalt

Qt 4.7 with Visual Studio 2010 and static linking

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


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




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


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)


Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.