Building Qt 5.12 LTS for Raspberry Pi on Debian Stretch

11/12/2018 - 17:08
Average: 5 (1 vote)

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 5.12 LTS, the Long Time Support branch.

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, they are described in the Optional features table below.

Note: This is not fully tested yet

Building Qt on the Raspberry Pi is quite straightforward and in short consist of the following steps:

  1. Downloading sources of Qt
  2. Checking the Qt source package integrity
  3. Preparing the sources for building
  4. Installing required dependencies
  5. Installing optional dependencies
  6. Fix for EGL library detection
  7. Configuring the Qt build
  8. Compiling Qt
  9. Installing the Qt build

This tutorial is written for the full source of version 5.12, it is fully possible to build only parts using the split up Qt submodule sources packages, but this tutorial will not go into that at this time.

Tutorial changelog

As this tutorial evolves over time, changes are logged here.

  • 10.12.2018 - Initial (beta) version for Qt 5.12 published

Storage space and memory 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 full Qt sources itself takes around 2.4GB, the build result around 625MB and the installation 155MB. A minimum of 8GB SD card is highly recommended. Running out of disk space after hours of compiling can be extremely annoying, trust me.

Compiling Qt takes quite a lot of memory, especially if trying to do a parallel build. Some parts take even too much memory and we need to disable building of them. It is highly recommened to enable at least 200MB of swap and also consider adjusting the system/GPU memory-split for the time of compilation, especially if parallel building.

Build Qt for Raspberry Pi

Download the Qt 5.12 source archive

Download the single source tar file from download.qt.io, version 5.10.1. The package is quite large, 487MB, so depending on your bandwidth it might take some time to download, grab a coffe or continue with the dependecies while the sources are downloading.

wget http://download.qt.io/official_releases/qt/5.12/5.12.0/single/qt-everywhere-src-5.12.0.tar.xz

Check archive MD5 hash

Just to make sure the download was succesfull and is what it should be, check the MD5 hash of the archive with:

md5sum qt-everywhere-src-5.12.0.tar.xz

It should be:

af569de3eb42da4457b0897e5759dc91  qt-everywhere-src-5.12.0.tar.xz

Un-tar the source archive

Un-tar the source archive in a suitable location, with enough free space (~2.8GB). This will take about 13 minutes on a Raspberry Pi 3+ and even more on an older model, so go grab of coffe again. You can of course start installation of the build dependecies while you wait.

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

Install required build dependencies

You will need to install plenty of packages to be able to build Qt. Some of the Qt features are optional, for example support for various databases and if you don't need a specific feature you can skip building the support. Or the other way around, if you need a specific feature you might need to install more packages. See the table below for a list of some optional features and the required development packages you need to install. But first, start by updating your package cache so everything is fresh:

apt-get update

Then continue with package installation.

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 additional 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 Packages to install Configure option
Bluetooth
apt-get install bluez libbluetooth-dev
 
gstreamer multimedia framework support
apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly \
gstreamer1.0-plugins-bad libgstreamer-plugins-bad1.0-dev \
gstreamer1.0-pulseaudio gstreamer1.0-tools gstreamer1.0-alsa
 
Linux ALSA Audio support
apt-get install libasound2-dev
 
Pulseaudio support
apt-get install pulseaudio libpulse-dev
 
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
 
X11 support
apt-get install libx11-dev libxcb1-dev libxkbcommon-x11-dev libx11-xcb-dev libxext-dev
 
Accessibility
apt-get install libatspi-dev
 
SCTP [1][2]
apt-get install libsctp-dev
-sctp

Broadcom EGL library filename fix

On Raspbian Stretch the OpenGL library files have been renamed (1, 2)so that they wouldn't conflict with Mesa installed ones. Unfortunately Qt configure script is still looking for the old names. There are a couple of solutions for this:

  1. Run rpi-update and install bleading edge firmware and kernel. Then you are done.
  2. Patch the Qt configuration to look for the correct libraries. See QTBUG-62216 for details.
  3. Create symlink manually.

    In /opt/vc/lib run:

    sudo ln -s libbrcmEGL.so libEGL.so

    sudo ln -s libbrcmGLESv2.so libGLESv2.so

    sudo ln -s libbrcmOpenVG.so libOpenVG.so

    sudo ln -s libbrcmWFC.so libWFC.so
  4. Use the libbrcm* prefixed names and give them to configure in QMAKE_LIBS_* instead.

     

Create a shadow build directory outside of the Qt 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. Remember to adjust any paths in the commands.

mkdir build
cd build

Configure

Qt needs to be configured for your system and there a couple of ways to do that. When building Qt for a particular device (-device option) it makes an assumption that your are cross-compiling even if you are building natively. This makes it necessary to do some tricks to get things like pkg-config to work. But fortunately we can build natively by specifying the Pi specific variables directly to configure and skip the "build for device by cross-compilation" way.

Configure the Qt build (New way)

We configure Qt for a native build and set device specific settings, like libraries, default QPA plugin to use, etc directly on the configure command line. This makes it also easy to optimize for any specific Raspberry Pi board type.

PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig \
../qt-everywhere-src-5.12.0/configure \
-v \
-opengl es2 -eglfs \
-no-gtk \
-opensource -confirm-license -release \
-reduce-exports \
-force-pkg-config \
-nomake examples -no-compile-examples \
-skip qtwayland \
-skip qtwebengine \
-no-feature-geoservices_mapboxgl \
-qt-pcre \
-no-pch \
-ssl \
-evdev \
-system-freetype \
-fontconfig \
-glib \
-prefix /opt/Qt5.12 \
-qpa eglfs \
QMAKE_CFLAGS="-march=armv8-a -mtune=cortex-a53 -mfpu=crypto-neon-fp-armv8" \
QMAKE_CXXFLAGS="-march=armv8-a -mtune=cortex-a53 -mfpu=crypto-neon-fp-armv8" \
QMAKE_LIBS_EGL="-lEGL -lGLESv2" QMAKE_LIBS_OPENVG="-lEGL -lOpenVG -lGLESv2" \
QMAKE_LIBDIR_OPENGL_ES2=/opt/vc/lib QMAKE_INCDIR_OPENGL_ES2="/opt/vc/include /opt/vc/include/interface/vcos/pthreads /opt/vc/include/interface/vmcs_host/linux" \
QMAKE_LIBDIR_EGL=/opt/vc/lib QMAKE_INCDIR_EGL="/opt/vc/include /opt/vc/include/interface/vcos/pthreads /opt/vc/include/interface/vmcs_host/linux" \
QMAKE_LIBDIR_OPENVG=/opt/vc/lib QMAKE_INCDIR_OPENVG="/opt/vc/include /opt/vc/include/interface/vcos/pthreads /opt/vc/include/interface/vmcs_host/linux" \
-DEGLFS_DEVICE_INTEGRATION=eglfs_brcm

 

Configure the Qt build (Old Way!)

This is here for historical reasons or in case the above does not work.

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 and the only one tested to work!
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 much 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 or you can try adding plenty of swap.

If you like, go hand ahead and use any suitable custom prefix instead of /opt/Qt5.12 provided in the example configure command.

Run configure with the following options (all on one line! And yes, PKG_CONFIG_LIBDIR & PKG_CONFIG_SYSROOT_DIR environment variables come before configure !):

PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig \
PKG_CONFIG_SYSROOT_DIR=/ \
../qt-everywhere-src-5.12.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 -no-kms -nomake examples -no-compile-examples -no-pch \
-skip qtwayland -skip qtwebengine -no-feature-geoservices_mapboxgl \
-qt-pcre -ssl -evdev -system-freetype -fontconfig -glib -prefix /opt/Qt5.12

Check the configure result

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 3+ this should run fine without getting throtled too much.

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).

Note: It might happen that parallel build needs too much memory, in that case run with just one process or try -j2, -j3

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.12 installed in /opt/Qt5.12 ready for use. To configure your Qt project(s) to build with this version run qmake from the installation directory:

/opt/Qt5.12/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 5.12 on your Pi, Happy coding!

 

Changelog: 
10/12/2018 - 10:38
Keywords: 
Qt, Raspberry Pi