Static Links and Qt Deployment

I am trying to deploy (publish) a simple qt application that I made recently, but got stuck in the qt libs static linking.

I followed the qt docs tutorial to re-build qt and my application statically. But to build the release, qtgui / qtcore dll is still required without any obvious reason, I wonder if anyone has seen such problems before? Or better yet, successfully resolved it?

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

+54
windows static qt deployment
Jun 18 '09 at 7:10
source share
6 answers

I wrote a static linking guide

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

(because it can get quite large, especially for simple programs). You can also check out the BitRock installer, which is free for open source projects.

In short, it turns out to be a little more complicated if you use something that Qt considers a plugin, for example, support for most types of images (JPEG, GIF) or databases. For example, if you want to include support for Oracle and GIF images for your icons, you add the following to your .PRO file:

QTPLUGIN += qsqloci qgif CONFIG += static 

Then you need to:

 #include <QtPlugin> 

in your project and import any used plugins. You need to change this order of settings so that it can be compiled using dynamic linking (for example, when debugging or adding features), although this can be easily automated. There are also considerations when building Qt libraries for use with static linking, although Qt instructions will at least start working.

+39
Oct 31 '09 at 16:17
source share

With Qt 5.5, everything is pretty simple. There are the following orthogonal settings that you pass configure when building Qt:

  • Do you need a static Qt library?

    -static should be passed to configure

  • Do you want the build of Qt and your application to use the static C ++ runtime?

    -static-runtime parameter must be passed to configure

  • Do you want to target XP?

    -target xp parameter must be passed to configure

    Alternatively, follow the instructions on this blog post .

    Qt Creator did not support XP targeting automatically, at least until version v.3.5.0, because it did not configure the environment for the build tools properly. You must change the build environment manually for the blog post .

+12
Sep 16 '15 at 16:19
source share

Also, keep in mind that your static build will dynamically bind to the runtime of the visual studio!

See this faq ( link to the online archive, in case the link goes away ):

Why does statically-built Qt use Visual Studio dynamic runtime libraries? Do I need to deploy them with my application?

Qt is built using the -MD (d) switch, which is associated with C / C ++ dynamic runtime libraries. This is necessary because we had memory problems when using anything other than the -MD (d) flag, and it is generally recommended that you use it. You should not change this flag yourself for your application, because it conflicts with the way the Qt library is built if you change the flag to -MT. You should also not change it for Qt, as this can cause problems.

Qt is still created statically using the -static option, but that means you do not need to distribute Qt-dll when you deploy your application. You will have to distribute the C runtime (although they do not yet exist on the target machine), see our deployment documentation http://doc.qt.io/qt-5/deployment-windows.html#application-dependencies ,

+6
Jan 26 '11 at 13:16
source share

I just compiled the application statically (Debug) with the QT (5.9) plugins, with VS (2015) (Win).

a) Add to your code.

 #include <QtPlugin> Q_IMPORT_PLUGIN (QWindowsIntegrationPlugin); 

b) Add the following link paths

 \5.9.0_x86_static_install\lib \5.9.0_x86_static_install\bin \5.9.0_x86_static_install\plugins \5.9.0_x86_static_install\plugins\platforms \5.9.0_x86_static_install\plugins\imageformats 

c) Add a list of static QT libraries and internal VS libraries to the list of links.

 version.lib imm32.lib shlwapi.lib rpcrt4.lib Ws2_32.lib Mpr.lib Netapi32.lib Rpcrt4.lib Iphlpapi.lib winmm.lib gdi32.lib advapi32.lib msimg32.lib UxTheme.lib translatord.lib preprocessord.lib d3d9.lib dxguid.lib libEGLd.lib libGLESv2d.lib iphlpapi.lib psapi.lib ws2_32.lib Dwmapi.lib Qt5CoreD.lib Qt5Guid.lib Qt5Xmld.lib Qt5Widgetsd.lib Qt5Networkd.lib Qt5Winextrasd.lib Qt5PlatformCompositorSupportd.lib qicod.lib qtmaind.lib qtlibpngd.lib qtharfbuzzd.lib qtpcre2d.lib qwindowsd.lib Qt5FontDatabaseSupportd.lib Qt5ThemeSupportd.lib Qt5EventDispatcherSupportd.lib Qt5AccessibilitySupportd.lib qtfreetyped.lib 

Kevin Higgins

+1
Jun 20 '17 at 14:12
source share

msys2 has a pre-built static Qt5 package

... which, using CMake, when the CMAKE_AUTOSTATICPLUGINS target property is set, also binds all available plugins. (this is currently only allowed with patches downstream, unofficial, but it achieves the goal)

If you use qmake, this will at least save you the effort of creating it.

+1
Oct. 15 '17 at 2:05 on
source share

you need to add CONFIG + = static to your .pro file. if this does not work, you must provide additional information.

0
Jun 18 '09 at 8:50
source share



All Articles