qtdynamicstatic

How to compile Qt plugins statically and dynamically


I came through terms dynamic and static compiling in Qt. Could some one explain the difference and how there are done in practice.


Solution

  • First thing, you need to compile the dynamic plugin as a dll and the static plugin as a static library.

    So for the static add something like this to your project file

    CONFIG *= staticlib # 
    

    The dynamic version is just a standard dll, i.e.

    CONFIG *= dll
    

    Second, specify that you are compiling a plugin:

    CONFIG *= qt plugin
    

    So what's the difference between those two?

    1. The dynamic plugin is a dll, it will build in the plugins directory which has to be in the application path when running your app. This can be easily forgotten when deploying the app (and then you might end up with no thumbnails etc. )
    2. The static plugin needs to be linked into your application (typically using the QTPLUGIN macro within the profile). Just linking the static plugin library using the libs *= plugin_name syntax works as well.

    I prefer 2. because it gives you more control over your build environment and makes the app deployment less buggy...