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 ?
With Qt 5.5, things are quite easy. There are following orthogonal settings that you pass to
configure
when building Qt:Do you want a static Qt library?
-static
option should be passed toconfigure
Do you want the build of Qt, and of your application, to use a static C++ runtime?
-static-runtime
option should be passed toconfigure
Do you want XP targeting?
-target xp
option should be passed toconfigure
Additionally, follow the instructions from this blog post.
Qt Creator didn't support XP targeting automagically at least until v.3.5.0 since it doesn't set up the environment for the build tools properly. You have to modify the build environment manually per the blog post.
I recommend you to use linuxdeployqt this tool. It can help solve most of the dependency problems. And I use it to package my qt application successfully.
msys2 has a pre-built static Qt5 package
… which, using CMake, when the
CMAKE_AUTOSTATICPLUGINS
target property is set, also links all available plugins. (this, currently, is only enabled through downstream patches, unofficial, but it reaches the goal)If you use qmake this at least spares you the effort to build it yourself .
I just compiled an application statically (Debug) with QT Plugins(5.9), with VS (2015) (Win).
a) Add to your code.
b) Add the following to the link paths
c) Add the list of QT static libraries and internal VS libraries to your link list.
Kevin Higgins
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:
You will then need to:
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.
Also, be aware that your static build will still link to the visual studio runtimes dynamically!
See this faq (internet archive link, in case the link goes away) :