How to build Qt 5 statically

15,489

The Qt shared libraries don't exist on the other computer you tested it on. So you need to either:

  1. Copy the shared libraries to your other machine. Or...
  2. Create a static Qt build to link with your application.

It's not sufficient to just add CONFIG += static to your .pro file, you also need Qt static libraries. So to do #2 you'll need to get the Qt source code and build it yourself.

Also, Qt is licensed under the LGPL so you'll need to be aware of that when static linking. There are some who believe that the LGPL does not allow static linking (unless you LGPL your own code) and others who believe that it does (so long as you're willing to release the object code for your app). But that's a whole other discussion.

Share:
15,489

Related videos on Youtube

Mils
Author by

Mils

I have a diverse technological background including Javascript, Angular/React, Typescript > C/C++, and quite a few others.

Updated on September 14, 2022

Comments

  • Mils
    Mils over 1 year

    I worked with Qt Creator 2.6.2 based on Qt 5.0.1 in a linux environnement. The application works fine on the computer where I made the compilation but when I execute it on another computer I got errors like :

    error while loading shared libraries: libQt5WebKitWidgets.so.5: cannot open shared object file: No such file or directory
    error while loading shared libraries: libxslt.so.1: cannot open shared object file: No such file or directory
    

    I found some solutions in this link (some links are dead).

    So I added to my .pro file this line :

    CONFIG += static
    

    To compile my project statically.

    I thought the file I'll get will be larger but I got the same size and the same errors.

    Thank you.

    • Md. Minhazul Haque
      Md. Minhazul Haque about 11 years
      Grab the source, and build with ./configure -static -release
    • dtech
      dtech
      You need to build do a static Qt build in order to compile a project statically.
    • cubuspl42
      cubuspl42
      And keep the licensing issues in mind.
  • JBentley
    JBentley about 10 years
    Regardless of what "some believe", under the terms of the terms of the LGPL, which you can read for yourself here you can link statically as long as you provide the means for the end-user to relink at will. Section 4(d)(0) is clear on this point.
  • Cutterpillow
    Cutterpillow over 9 years
    @JBentley Sorry for the late reply... I happen to agree with you completely, but other people that I’ve encountered believe differently, regardless of what the text of the license states.