Building Qt 6.2 for Raspberry Pi on Raspberry Pi OS

14/09/2021 - 18:54
Average: 5 (1 vote)

Guide on how to build Qt 6.2 (currently beta 4) for use on a Raspberry Pi running Raspberry Pi OS.

Note: This is guide is preliminary, a beta if you like.

Guide on how to build Qt 6.2 (Currently beta 4 release) components for use on a Raspberry Pi running Raspberry Pi OS. The configuration and build differs quite a lot from how Qt 5 is built as the build system is now using cmake and ninja, instead of the older qmake and make combo.

Note: This guide is preliminary and can be considered beta quality. There are some issues with building with the Broadcom libraries.

This tutorial is written for the split components version of Qt 6.2 instead of the all components one. This makes it much faster to get up and running with only the components you actually need. Building Qt 6 for and on the Raspberry Pi is still pretty straightforward, there are some Pi specific configurations that needs to be made, but in short it consist of the following steps:

  1. Downloading sources of Qt 6.2 components
  2. Checking the Qt 6.2 source package integrity
  3. Preparing the sources for building
  4. Installing all required dependencies
  5. Installing any optional dependencies
  6. Configuring the Qt 6.2 base build
  7. Compiling Qt 6.2 base
  8. Installing the Qt 6.2 base

And for any extra components it is basically a matter of:

  1. Install dependencies
  2. Extract sources
  3. Configure
  4. Build
  5. Install
  6. Goto 1

Installing cmake from source

The build system has changed in Qt 6 and instead of qmake and make, it now uses cmake and ninja. We will need need to install cmake from source, as the one provided in the Raspberry Pi OS package repository (surprise!) is too old. Building cmake is quite easy, it needs to first bootstrap itself and the we can build and install it. We will install our cmake so that it won't conflict with the distribution provided one. Just remember to call it using full path so the correct version gets used. Luckily the version available of ninja is good enough.

As we need to be able to build software, make sure the essential build tools are installed with:

apt install build-essential

Build and install cmake from sources

wget https://github.com/Kitware/CMake/releases/download/v3.20.5/cmake-3.20.5.tar.gz
tar xf cmake-3.20.5.tar.gz
mkdir cbuild && cd cbuild
../cmake-3.20.5/bootstrap --prefix=/opt/cmake --parallel=4 && make -j4 && make install

Now we have a new enough cmake installed that we can use for building Qt 6.2!

Install required build dependencies

You will need to install plenty of packages to be able to build Qt 6.2. Some of the Qt 6.2 features are optional and can be either left our or included, depending on your particular needs. For example support for various databases (PostgreSQL, MySQL/MariaDB) 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 development packages.

Some features are not strictly required but might still be nice to have, for example support for the webp image format is optional, but these days it is already widely used so might be good to include.

See the table below for a list of some optional features and the required development packages you need to install.

Optional features for base Qt
Optional feature Packages to install Configure option
Support for various databases (PostgreSQL, MariaDB/MySQL)

libpq-dev libmariadbclient-dev

 

Printing support using CUPS

libcups2-dev

 
X11 support

libx11-dev libxcb1-dev  libxext-dev libxi-dev libxcomposite-dev libxcursor-dev libxtst-dev libxrandr-dev libfontconfig1-dev libfreetype6-dev libx11-xcb-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev  libxcb-glx0-dev  libxcb-keysyms1-dev libxcb-image0-dev  libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync-dev libxcb-xfixes0-dev libxcb-shape0-dev  libxcb-randr0-dev  libxcb-render-util0-dev  libxcb-util0-dev  libxcb-xinerama0-dev  libxcb-xkb-dev libxkbcommon-dev libxkbcommon-x11-dev

 
QtWebEngine

Required: flex bison gperf libre2-dev libnss3-dev libdrm-dev

Optional: libxml2-dev libxslt1-dev libminizip-dev libjsoncpp-dev liblcms2-dev libevent-dev libprotobuf-dev protobuf-compiler

Optional but unusable versions in raspbian: libopus-dev libvpx-dev

 
libzstd libzstd-dev  
Accessibility

libatspi-dev

 
SCTP [1][2]

libsctp-dev

-sctp

Install any package from the above table with apt install.

But first, start by updating your apt package cache so everything is fresh:

apt update

Then continue with required package installation below.

Install the bare minimum required development packages for building Qt 6.2 with apt:

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

Remove libzstd-dev

This might sound strange, but just in case, make sure that you DON'T have libzstd development package installed. Qt 6 will use the system provided one if installed and it will lead to problems as the rcc tool will fail with a Bus Error inside libzstd. So, remove libztsd-dev if it is installed:

apt remove libzstd-dev

Building Qt 6.2 base

Qt Base provides the core parts of Qt and needs to be built and installed before anything else.

Download Qt 6.2 base sources

wget https://download.qt.io/development_releases/qt/6.2/6.2.0-beta4/submodules/qtbase-everywhere-src-6.2.0-beta4.tar.xz

Configure, build and install Qt 6.2 base

Extract the sources:

tar xf qtbase-everywhere-src-6.2.0-beta4.tar.xz

Create a build directory:

mkdir qtbasebuild && cd qtbasebuild

Optional: Create a cmake toolchain file

You might need to make a cmake toolchain file in case you are building for some other type of system, for example you are going to run Qt on the armv6 based Pis but build on something faster (arvmv7 or armv8). This is not needed if the Qt build will be run on the current device type only.

To create a cmake toolchain file, tc.cmake, fire up your favorite editor. Put it in the qtbase source directory. The contents for the file is, depending on target architecture (Note: only armv7 has been tested):

CMAKE_TOOLCHAIN_FILE Examples

For armv6

set(CMAKE_CROSSCOMPILING FALSE)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv6)
set(TARGET armv6-linux-eabi)
For armv7
set(CMAKE_CROSSCOMPILING FALSE)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7)
set(TARGET armv7-linux-eabi)
For armv8
set(CMAKE_CROSSCOMPILING FALSE)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv8)
set(TARGET armv8-linux-eabi)

 

Configure the Qt 6.2 build

Then run the configuration (adjusting prefix if needed, remove CMAKE_TOOLCHAIN_FILE parameter if not used):

/opt/cmake/bin/cmake -G Ninja \
-DCMAKE_INSTALL_PREFIX=/opt/Qt/6.2.0-beta4-armv7l \
-DQT_FEATURE_opengles2=ON \
-DQT_FEATURE_opengles3=ON \
-DCMAKE_TOOLCHAIN_FILE=tc.cmake \
-DQT_AVOID_CMAKE_ARCHIVING_API=ON ../qtbase-everywhere-src-6.2.0-beta4

Check the configuration summary output that everyhting needed was succesfully detected, and if so start the build.

Build Qt 6.2 base

/opt/cmake/bin/cmake --build . --parallel 4

Install Qt 6.2 base

/opt/cmake/bin/cmake --install .

Building Qt submodules

Building submodules in quite straightforward, you download the source for the submodule you require, extract the archive, configure sources, build the sources and install the result. The only thing you need to keep in mind is to build them in the correct order to satisfy dependencies. The following (incomplete at this time) table describes the required dependency submodules and any development packages that are needed.

 

Component dependencies on packages and other Qt submodules
Module Required submodules Development packages required Description Build time (Pi 4)
qtimageformats   libmng-dev libjasper-dev Support for loading various extra image formats  
qtsvg     Support for SVG vector graphics  
qtshadertools     Tools for the cross-platform Qt shader pipeline  
qttools        
qtserialbus     Serial bus (CAN bus, ModBus) support ~2m
qtserialport qtserialbus   Serial port support < 1m
qtlocation qtserialport   Positioning (GPS) and location (Map) services < 3m
qtdeclarative        
qtquickcontrols2    

UI Control for QtQuick

Note: Part of qtdeclarative submodule since beta 3

 
qtmultimedia qtdeclarative

For gstreamer backend:

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

For pulseaudio support:

pulseaudio libpulse-dev

For plain ALSA:

libasound2-dev

Multimedia (audio/video) support  
qtsensors qtmultimedia   Support for various device sensors  
qtnetworkauth     Network authentication protocol support (OAuth) < 1m
qtconnectivity   bluez libbluetooth-dev Bluetooth and NFC connectivity support  
qtwebsockets qtdeclarative   Websockets support ~1m
qtcharts qtdeclarative   Charting controls ~10m
qtwayland   libwayland-dev Wayland support ~10m
qtvirtualkeyboard qtsvg   Provides on-screen keyboard ~4m
qt5compat     Unsupported Qt 5 compatibility code ~2m

 

Configure, build and install with

/opt/Qt/6.2.0-beta4-armv7l/bin/qt-configure-module . && /opt/cmake/bin/cmake --build . --parallel 4 && /opt/cmake/bin/cmake --install .
Keywords: 
Qt