Building static Qt 5

From Moondust Wiki
Jump to navigation Jump to search

This is a detail guilde how to build the static version of the Qt framework. Static build of Qt allows you to build solid applications which will work without lots of additional *.DLL/*.SO or *.DYLIB files because everything will be hardcoded into your application.

Introdution

Static version of Qt allows you to build solid application files without packing of a lots of dependent libraries.

Don't forget that with static version of Qt you can legally release your applications if there are Open-Source! (With GPLv3 license). If you wants to use static Qt build in commercial development of closed-source applications, you should buy commercial license for that purpose.

Preparation

Installing dependencies

Before start build you must install all necessary dependencies:

Install on Debian/Ubuntu/Mint

sudo apt-get install gcc g++ make wget
sudo apt-get install build-essential
sudo apt-get install "^libxcb.*" libx11-xcb-dev libxrender-dev libfontconfig1-dev libxkbcommon-dev udev mtdev-tools webp
sudo apt-get install mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libgles2-mesa libgles2-mesa-dev

Download

At first, you must to download entire source code tarball from official Qt site:

Download Qt 5.5.1 tar.gz Note: if this link is outdated, you can find newer version of Qt sources here:

Qt open-source Download page

Unpacking

Unpack everything from the tarball into any folder (on Linux or on Mac OS X): tar -xvf qt-everywhere-opensource-src-5.5.1.tar.gz

Removing of glitchy Jasper library

This library provides JPEG2000 image format support, but in the PGE it is useless (main image formats in the PGE are PNG, GIF and BMP), and also causes a random crashes of Qt applications built with your Qt build.

To resolve next issues, recommended to remove building of JPE support:
because disabling of JPE building is not provided by ./configure script given with Qt sources, we must remove building of JPE weself:

  • make a kill_jasper.sh file in parent folder of Qt sources folder
  • on OS X: install via homebrew the coreutils and gnu-sed
  • open a text editor (On OS X: Don't use TextEditor.app, because it makes invalid code!, use text editor from XCode or use nano) and paste next content into it:
#!/bin/bash
QTP=qt-everywhere-opensource-src-5.5.1

sed -i 's/qtCompileTest(jasper)/#qtCompileTest(jasper)/g' $QTP'/qtimageformats/qtimageformats.pro'
sed -i 's/jp2 \\/#jp2 \\/g' $QTP'/qtimageformats/src/plugins/imageformats/imageformats.pro'
rm -f $QTP'/qtimageformats/src/3rdparty/jasper.pri'
rm -Rf $QTP'/qtimageformats/src/3rdparty/jasper'
read -n 1
  • open command line and execute this script by "bash ./kill_jasper.sh" command

Same for OSX with gnu-sed:

#!/bin/bash
QTP=qt-everywhere-opensource-src-5.5.1

gsed -i 's/qtCompileTest(jasper)/#qtCompileTest(jasper)/g' $QTP'/qtimageformats/qtimageformats.pro'
gsed -i 's/jp2 \\/#jp2 \\/g' $QTP'/qtimageformats/src/plugins/imageformats/imageformats.pro'
rm -f $QTP'/qtimageformats/src/3rdparty/jasper.pri'
rm -Rf $QTP'/qtimageformats/src/3rdparty/jasper'
read -n 1

Configure

Open console then change current directory to new folder which you has been unpacked. then Copy-paste this into console ans press ENTER:

Linux Mint / Debian

./configure -static -release -nomake examples -nomake tools -prefix ~/Qt/5.5.1_static -qt-xcb \
-qt-libpng -no-libjpeg -qt-zlib -qt-pcre -gtkstyle -opensource -confirm-license -gtkstyle -opengl -qt-freetype -c++11

Mac OS X

./configure -static -release -nomake examples -nomake tools -prefix ~/Qt/5.5.1_static_osx \
-qt-libpng -no-libjpeg -qt-zlib -qt-pcre -gtkstyle -opensource -confirm-license -gtkstyle -opengl -qt-freetype -no-ssse3

then wait while configuring will be finished (you will need to wait ~30...60 min)

Build

make

(you will wait ~1.2...2 hours)

Hint: you can speed-up building process with adding -r argument, and adding -j x (where x - number of concurrent jobs. For example -j 4)

make -r -j 4

Installation

make install

(you will wait ~10..30 min)


Usage

Built Qt will be located at ~/Qt/5.5.1_static or ~/Qt/5.5.1_static_osx on Mac OS X. To configure your Qt application to be built with static Qt version, you need to call ~/Qt/5.5.1_static/bin/qmake while you in your project folder, and other steps are same as you build with regular Qt version.

If you wants to plug static build of Qt into Qt Creator, just make a new toolchain with your default compiler (GCC, CLang or MinGW on Windows systems) and debugger, and with your static build of Qt (find QMake in the bin subdirectory of your static Qt build)

Note: Carefully transfer packages with a static build of Qt, you should keep same absolute path (because it is hardcoded) if you don't want to rebuild Qt again.