Build Qt Statically for Linux

In this post I’ll describe how to build a static version of Qt under Linux (Ubuntu flavor) and I will use Qt 5.7.0 and Ubuntu 16.04 64-Bit for that matter. Static builds ease the process of app deployment under Linux cause it is quite complex (much more complex than Windows and Mac OS X) so without further ado, here it is.

First you need to download Qt sources from the following link:

https://download.qt.io/archive/qt/

You usually need to get the latest sources and single module that contains all sources. In my case (Qt 5.7.0) it was here.

https://download.qt.io/archive/qt/5.7/5.7.0/single/qt-everywhere-opensource-src-5.7.0.7z

Download and extract it. (note that you might need to install p7zip if you don’t have it already)

Let’s say you extracted the sources in the folder below:

/home/amin/Downloads/qt-everywhere-opensource-src-5.7.0

Open up a terminal and enter the following commands:

cd Downloads/qt-everywhere-opensource-src-5.7.0


Next enter the following command and note that you need to replace “/home/amin/Qt570static” with your own folder for Qt build:

sudo ./configure -static -prefix "/home/amin/Qt570static" -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -qt-xcb -opengl desktop -qt-sql-sqlite -make libs -nomake tools -nomake examples -nomake tests

You will be asked to choose the edition of Qt. Type “o” to select the open source edition and press enter to proceed.

Then you will be asked to confirm the license. Type “yes” and press enter.

When configuration’s done, type the following command:

sudo make

Now wait for awhile. Maybe quite a while if you use an old laptop for Linux development, like me.

After the build is finished, enter the following final command to get your static build kit under “/home/amin/Qt570static” folder that you provided to configure command.

sudo make install

Voila, it’s done. You have your Qt static build.

screenshot-from-2016-09-19-19-04-49


6 Replies to “Build Qt Statically for Linux”

    1. What do you mean by “open Qt”? It’s a kit, there’s nothing to open. If you mean Qt Creator, that’s not the topic of this article. Just download Qt Creator and use it with this kit. You need to configure Qt Creator to use your kit.

  1. Add the option -static-runtime to statically compile some others plugins that are usually loaded at runtime. You can also use -static-libgcc when linking to make sure there is no dynamic dependences with GCC libs.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.