Important: Please read the Qt Code of Conduct -

Qt Static Build with SQL plugins/libs

  • Hi, when I use the Qt help framework (QT += help), I feel that I introduce some plugin stuff like the SQL database, which is supposed to be also statically linked into the application. Still have no idea how to do this. However, when I list the linked libraries of the static built application (using ldd), there are still some shared SQL libraries which are not shipped with the system, meaning if you move onto anther machine, still need to install them for the application to run. => /usr/lib/x86_64-linux-gnu/ => /usr/lib/x86_64-linux-gnu/ => /usr/lib/x86_64-linux-gnu/

    In the configure of Qt static library, I saw some options related to SQL database, but have no idea how they are related:

      -sql-<driver> ........ Enable SQL <driver> plugin. Supported drivers:
                             db2 ibase mysql oci odbc psql sqlite2 sqlite tds
                             [all auto]
      -sqlite .............. Select used sqlite3 [system/qt]

    Is this the way or I should manually link to the static version of these SQL libraries? I'm using Qt5.12.0 on Ubunto16.04. Thanks.

  • Lifetime Qt Champion


    If you want a fully static application, then you have to link to all dependencies statically also.

    Just remember that you also have to abide by the licensing constraints if you are using the (L)GPL version of Qt.

  • Hi @SGaist Noted the license constraints with thanks.

    May I know how to statically link this sql library? I can link all my other libraries statically but this one seems was linked by the Qt Help module and still not sure how to tell Qt to link the static version? I tried add LIBS += .......libmysqlclient.a but it does not work. Qt still looks for the shared version

  • Lifetime Qt Champion

    Do you have both in the same folder ?

  • @SGaist yes they are both in /usr/lib/x86_64-linux-gnu/

  • Lifetime Qt Champion

    Then you should remove the dynamic version of the library.

  • @SGaist Noted. Is there possible any way that I can tell Qt to link to the static version when I built the static Qt from source?

  • Lifetime Qt Champion

    IIRC, you would have to put the whole path to the file that needs to get linked.

Log in to reply