Yujian Yao

Software Engineer

How to deploy your Qt application without any Dll files

04February2011

Running Qt on Ubuntu is great, because most of the supporting libraries are installed by default. However, to deploy a Qt application on Windows, you have to make sure that the application comes with all the Dll files, which I personally find annoying. Of course, it is possible to package the whole Qt application in one exe executable-by linked against the Qt libraries statically.

Following the guide here, and you will still get a frustrating error asking for the mingwm10.dll file. The only way to avoid this is to link statically against the compiler library as well.

To do so, first open the qmake.conf here: %qtdir%\mkspecs\win32-g++\qmake.conf. %qtdir% is where your Qt libraries are installed, normally it should be in some place like C:\Qt\2010.05\qt. Look for the line with "QMAKE_LFLAGS=", and change it from

QMAKE_LFLAGS		= -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
to
QMAKE_LFLAGS		= -static -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
i.e. add a '-static' argument.

Next, go to Qt Command Prompt (can be found in the start menu), issue these commands:

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

This will recompile the whole Qt library to allow static linking. It can take a very long time(2+ hours on my laptop).

Now you can modify your project to tell the compiler to compile your application statically. Add this line in your .pro file:

CONFIG += staticlib

Compile your project in release mode afterwards, this should give you a .exe file with a size >5m. The application should now be able to run on other Windows machines without any Qt libraries.

Of course we can reduce the size of the application since it probably contains some Qt libraries that are not used at all. Go the Qt Command Prompt, and enter to the directory containing your application, type:

strip -s *.exe
where *.exe is the name of your application.

This step will not reduce much of the size(maybe a few k). A good idea is to use UPX to compress your application afterwards, which I haven't tried though.