Windows – Qt static linking and deployment

deploymentqtstaticwindows

I am trying to deploy(release to public) a simple qt application I made recently, but got stuck at static linking qt libs.

I followed the guide on qt docs to re-build qt and my app statically. But the release build still require qtgui / qtcore dll for no apparent reasons, I wonder if anyone has seen this kind of problems before ? Or even better, has successfully resolved it ?

http://doc.qtsoftware.com/4.5/deployment-windows.html

Best Answer

I wrote a guide to static linking

and How to build Qt static with multiple compilers and keep it small

(because it can get pretty big, especially for simple programs). You may also want to check out the BitRock installer, which is free for open source projects.

In short, it turns out to be a little more complex if you are using anything Qt thinks of as a plugin, such as support for most image types (JPEG, GIF) or databases. For example, if you want to include support for Oracle DBMS and GIF images for your icons, you add the following to your .PRO file:

QTPLUGIN += qsqloci qgif
CONFIG += static

You will then need to:

#include <QtPlugin>

in your project, and import any plugins used. You need to change these settings back order to get it to compile with dynamic linking again (like when debugging or adding features), though this can be easily automated. There are also considerations when building the Qt libraries for use with static linking, though the Qt instructions will at least get you started.