Building Qt 5.10 for Raspberry Pi on Debian Stretch

18/01/2018 - 17:21
Average: 3.7 (3 votes)

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 explain how to build Qt, a time of writing the latest, version 5.10.0.

These instructions will build version of Qt that uses the eglfs interface by default and therefore runs applications fullscreen. You can optionally add X11 and/or 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:

  1. Downloading sources
  2. Preparing the sources
  3. Installing required dependencies
  4. Installing optional dependencies
  5. Configuring the build
  6. Compiling
  7. Installing the build

This tutorial is written for the full source of version 5.10.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 2.4GB, the build result 4.0GB and the installation 155MB. A minimum of 16MB SD card is highly recommended. Running out of disk space after hours of compiling can be extremely annoying, trust me.

Changelog

  • 11.12.2017 - Initial version for Qt 5.10 published
  • 27.12.2017 - Fix download links and size
  • 11.01.2018 - X11 can be used too
  • 18.01.2017 - Fix Pi3 config option. Add VC4 option.

Download the Qt 5.10.0 source archive

Download the single source tar file from Qt.io, version 5.10.0. The package is quite large, 389MB, so depending on your bandwidth it might take some time to download, grab a coffe.

wget http://download.qt.io/official_releases/qt/5.10/5.10.0/single/qt-everywhere-src-5.10.0.tar.xz

Un-tar the source archive

Un-tar the source archive in a suitable location, with enough free space (~2.4GB). This will take 7-8 minutes on a Raspberry Pi 3 and even more on an older model, so go grab of coffe again.

tar xf qt-everywhere-src-5.10.0.tar.xz

Create a shadow build directory outside of the source tree

We will build Qt outside of the source tree, this way you can easily have different build version and easily also start over in case of any issues. You build location can be anywhere where there is enough space, for example an USB stick in case you are running out on your SD card.

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 specific needs.

Install required development packages

apt-get install build-essential libfontconfig1-dev libdbus-1-dev libfreetype6-dev libicu-dev libinput-dev libxkbcommon-dev libsqlite3-dev libssl-dev libpng-dev libjpeg-dev libglib2.0-dev libraspberrypi-dev

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 features
Optional feature Package install command
Bluetooth
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
Wayland support
apt-get install libwayland-dev
Accessibility
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:

Raspberry Pi ARM platform options
Platform option Device
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-rasp-pi3-g++ ARMv8 optimized version, runs on Raspberry Pi 3
linux-rasp-pi3-vc4-g++ ARMv8 optimized version, runs on Raspberry Pi 3. Using experimental VC4 KMS driver.
"This should allow accelerated EGL and OpenGL with eglfs via KMS/DRM/GBM (instead of the Broadcom-specific backend), under X11 with xcb."

Change the configure option linux-rasp-pi-g++ to any of the above to suit your needs.

Note that we are disabling the qtwebengine and mapboxgl as unfortunately compiling them requires more memory than any current Pi can provide. If you need these components, then consider doing a cross-compilation or build on the ARM device with more memory available. If you like, go hand ahead and use any suitable custom prefix.

Run configure with the following options:

PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig PKG_CONFIG_SYSROOT_DIR=/ \
../qt-everywhere-opensource-src-5.10.0/configure \
-v -opengl es2 -eglfs -no-gtk \
-device linux-rasp-pi-g++ -device-option CROSS_COMPILE=/usr/bin/ \
-opensource -confirm-license -release -reduce-exports \
-force-pkg-config -nomake examples -no-compile-examples \
-skip qtwayland -skip qtwebengine -no-feature-geoservices_mapboxgl \
-qt-pcre -ssl -evdev -system-freetype -fontconfig -glib -prefix /opt/Qt5.10

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.

Compile Qt

To compile run:

make

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 the components being built, speed of your SD card, etc . You can expect about 2-3 hours on a Raspberry Pi 3 when built with parallel make (make -j4).

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

make install

You should now have Qt 5.10 installed in /opt/Qt5.10 ready for use. To configure your Qt project(s) to build with this version run qmake from the installation directory:

/opt/Qt5.10/bin/qmake

You can of course also add it to your PATH.

Choosing platform

As explained in the introduction, this build will default to using the eglfs platform, meaning that no windowing environment is required to run GUI applications. You can choose the platform binaries will run against by suppling the "-platform" paramter when running them.

Qt Platform option examples
Platform Parameter
X11 -platform xcb
VNC -platform vnc
WebGL -platform webgl

Enjoy Qt on your Pi, Happy coding!

 

 

Keywords: 
Qt, Raspberry Pi, stretch