Home » Technology » Statically build QT 5 Applications on Ubuntu Linux

Statically build QT 5 Applications on Ubuntu Linux

Ok. So I finally managed to deploy my Qt app along with its dependencies after countless hours of googling. This was done on Ubuntu 12.04 with Qt 5.2.
This is how I did it:
1. Statically build Qt from the source using the following command :
./configure -opensource -confirm-license -prefix ./qtbase -make libs -make tools -release -opengl desktop -static -skip qtwebkit -no-icu -nomake tests -nomake examples

make -j -4

You can download the source from http://download.qt-project.org/official_releases/qt/5.2/5.2.1/single/qt-everywhere-opensource-src-5.2.1.tar.gz You cannot static build the installer version of Qt.
1. Open your Qt project and rebuild it. The Qt dependencies will be built into the app executable. Check with ldd to see if it was done correctly.
ldd ./<app_executable>

2. Now when you try to run this on a system without Qt it might ask for other third party dependencies which you see with ldd. Eg: libxcb-… You could either install these dependencies with apt-get on the target system or supply the libs with your app. That is: put the required .so files and their soft links into a directory named libs along with your executable.

3. After the lib dependency problems are fixed the App will give an error about missing Qt fonts. Easiest way to fix this is to supply the Qt fonts folder along with the app.

4. This link gives a good way of doing this: http://goblincoding.com/2013/11/07/deploying-qt-5-applications-on-ubuntu-12-04/

5. The summary of the above page is that you need to supply a small bash script to run your app. the script should be as follows:
#~/bin/bash
export LD_LIBRARY_PATH=./libs
export QT_QPA_FONTDIR=./fonts
./<app_executable>

The target system will now find the libs and the fonts from the directories you supplied and will run without issues. Hope this helped.
NOTE: I haven’t tried, but this script method should work even if you are supplying the Qt libs as well without statically building the qt source.

302 comments .

Govt Jobs By State

Get Jobs By Category


Share Your Thoughts, Queries & Problems With Us Using The Comment Form.
"armybharti.in is best Place To Discus Jobs & Exams."   Download Our Android app

Leave a Reply

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

Time limit is exhausted. Please reload the CAPTCHA.