Leon Anavi
IT Tips && Tricks


Created: 08.01.2011 13:27 Last Modified: 08.01.2011 13:40 Views: 32770
Keywords: exe, lib, mingw32-make, MSVCP90.dll, mt.exe, nmake, qmake, qt, release, standalone, static

Standalone Qt Application for Microsoft Windows


Qt is very attractive framework for software developers and sometimes they might need a standalone executable file for Microsoft Windows. This is an executable file that has no dependencies (aka do not require any dynamic linking to libraries). To create such a standalone version of a Qt application all require libraries should be embedded into the application using static linking. Please note that the size of the executable file will be larger.

Build a static version of Qt

The first step is to build a static version of Qt. The commands that should be executed depend on the desired platform MinGW (win32-g++) or Microsoft Visual Studio (win32-msvc).

Using MinGW

configure -static -release -no-exceptions
mingw32-make sub-src

Using Microsoft Visual Studio

Make sure that Microsoft Visual Studio is installed. Start the Visual Studio 2008 Command Prompt. Otherwise you may get errors due to wrong or missing paths. Execute the following commands in the directory where Qt is installed (for example: C:\Qt\4.6.3\):
configure -static -release -platform win32-msvc
nmake sub-src
Please note that reconfiguring and building Qt is a time consuming procedure. The duration may vary depending on the hardware of your computer.

Build a static application

Modify the pro file of the project by adding an option for static linking.
CONFIG += static

Using MinGW

To build the application run consecutively qmake and mingw32-make.
qmake Hello.pro

Using Microsoft Tools

To build the Qt project as a standalone executable file run qmake and nmake. After that you should execute mt.exe to embed a manifest inside the application to avoid error such as missing MSVCP90.dll when the application is started on other computers.
qmake Hello.pro
nmake release
cd release
mt.exe -manifest Hello.exe.manifest -outputresource: Hello.exe;1
Please note that the names of the manifest and the executable file depend on the name of your project.

External Links

Building static applications
Buildint static Qt on Windows
How to: Embed a Manifest Inside a C/C++ Application

  Home | About | Contact | Disclaimer | Sitemap 2009-2022 Leon Anavi. All rights reserved.