Building Qt 5.8 for Raspberry Pi on Debian Stretch
Raspbian based on Debian Stretch comes with an old (5.7.1) version of Qt that is already outdated and missing some features and modules. Afaik there are no up-to-date backports so the only way to get an up to date version version of Qt with all features enabled running on your Pi is to build it yourself.
This tutorial will use the LTS release branch, version 5.8.0. For version specific instructions, see: Qt 5.10
These instructions will build version of Qt that uses the eglfs interface and therefore runs applications fullscreen, without X11 support. You can optionally add Wayland support by installing the required development packages.
Building Qt on the Raspberry Pi is quite straightforward and in short consist of the following steps:
- Downloading sources
- Preparing the sources
- Installing required dependencies
- Installing optional dependencies
- Configuring the build
- Installing the build
This tutorial is written for the full source of version 5.8.0 but any older or later version should work just as well if you have specific needs.
It is fully possible to build only parts using the submodule specific packages, but this tutorial will not go into that.
Storage space requirements
Make sure you have enough disk space free on your on your Pi as building Qt requires a lot of disk space. The unpacked sources itself takes around 2GB, the build result 3.6GB and the installation 155MB.
Running out of disk space after hours of compiling can be very annoying, trust me.
- 04.09.2017 - Initial version published
- 06.11.2017 - Added note on Accessibility support, moved information into tables
- 09.11.2017 - Mention disk space requirements
Download the Qt 5.8.0 source archive
Download the single source tar file from Qt.io, version 5.8.0. The package is quite large, 354MB, so depending on your bandwidth it might take some time to download.
Un-tar the source archive
Un-tar the source archive in a suitable location, with enough space (2GB or more). This will take 7-8 minutes on a Raspberry Pi 3 and even more on an older model, so go grab of coffe.
tar xf qt-everywhere-opensource-src-5.8.0.tar.xz real 7m44.417s user 1m38.700s sys 0m25.820s
Create a shadow build directory outside of the source tree
A good practice is to build outside the source tree, especially if you would like to build with different options or for example own version for armv6 and arvm7. So, create a build directory where you have plenty of space (3GB or more) available and go into it:
mkdir build cd build
Install build dependencies
You will need to install plenty of packages to be able to build Qt. Some packages are optional and depends on your particular needs, they are described in the table below.
Install required development packages
apt-get install build-essential libfontconfig1-dev libdbus-1-dev libfreetype6-dev libicu-dev libinput-dev libxkbcommon-dev libsqlite3-dev libssl1.0-dev libpng-dev libjpeg-dev libglib2.0-dev libraspberrypi-dev
Note about OpenSSL 1.0.2 and 1.1.0
Debian Stretch has moved to OpenSSL 1.1.0 branch and unfortunately it is not source compatible with older versions of OpenSSL. Unfortunately Qt 5.8 does not support OpenSSL version 1.1.0 (there are patches available, try if you like). Fortunately Stretch does still provide a version of OpenSSL 1.0.2! That is why we install libssl1.0-dev above. The build will otherwise fail when building support for encrypted network connections.
Installing libssl1.0-dev might uninstall other packages, you can safely remove libssl1.0-dev after Qt is built and re-install any packages that might have been removed.
Install optional development packages
Qt consist of many modules, depending on your needs you might like to install additinal development packages to be able to enable support for these features in Qt. Check the table below for optional features and the required development packages that you need to install for them. Also make sure that the optional feature you need is found and enabled by the configure script by checking the output of configure run.
|Optional feature||Package install command|
apt-get install bluez libbluetooth-dev
|Audio & gstreamer multimedia||
apt-get install libasound2-dev pulseaudio libpulse-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-plugins-bad gstreamer1.0-pulseaudio gstreamer1.0-tools gstreamer1.0-alsa gstreamer-tools
|Support for various databases (PostgreSQL, MariaDB/MySQL)||
apt-get install libpq-dev libmariadbclient-dev
Printing support using CUPS
apt-get install libcups2-dev
apt-get install libwayland-dev
apt-get install libatspi-dev
Configure the build
For some odd reason Qt insists on being configured for cross-compiling, even when doing a native build. Fortunately we can work around it by specifying a couple of extra parameters to get everything detected properly.
You can choose to build a generic build that will work on all of the various Pi versions or specifc one that is optimized for your specific type of board. Choose one of:
|linux-rasp-pi-g++||ARMv6 compatible version, resulting binaries will run on all Raspberry Pi models. This is the default option.|
|linux-rasp-pi2-g++||ARMv7 optimized version, runs on Raspberry Pi 2 & 3|
|linux-rpi3-g++||ARMv8 optimized version, runs on Raspberry Pi 3|
Change the configure option linux-rasp-pi-g++ to any of the above to suit your needs.
Note that we are disabling the qtwebengine as unfortunately compiling it requires more memory than a Pi can provide.
Run configure with the following options:
PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig PKG_CONFIG_SYSROOT_DIR=/ \ ../qt-everywhere-opensource-src-5.8.0/configure -v -opengl es2 -eglfs -no-gtk \ -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=/usr/bin/ \ -opensource -confirm-license -reduce-exports \ -force-pkg-config -nomake examples -no-compile-examples \ -skip qtwayland -skip qtwebengine -release \ -qt-pcre -ssl -evdev -system-freetype -fontconfig -glib -prefix /opt/Qt5.8
Make sure that the configure script detects Raspberry Pi EGLFS, look for the following output:
QPA backends: DirectFB ............................... no EGLFS .................................. yes EGLFS details: ... EGLFS Rasberry Pi .................... yes
Now Qt should be configured properly with all features enabled that we need. If you need some of the optional features, make sure to check the configure result that they where properly detected.
To compile run:
or if you are using any of the quad-core Pis, append the -j4 parameter to build in parallel. Make sure you have proper cooling in this case.
The compilation time depends on hardware, speed of SD card and Qt configuration. With a generic configuration it takes just under 2 hours on a Raspberry Pi 3 when built with parallel make (make -j4). On a Raspberry Pi 2 it will take a bit more, a build of 5.4.2 took about 3 hours to complete.
Install the build
The compilation should finnish without any errors, if it does not, double check that you have all the dependecies installed and run configure correctly.
If all is well, install Qt by running
You now have Qt 5.8 installed in /opt/Qt5.8 ready to be used. To configure your Qt project(s) to build with this version run qmake from the installation directory: