Building Qt 6.2 for Raspberry Pi on Raspberry Pi OS

20/07/2021 - 14:19
No votes yet

Guide on how to build Qt 6.2 (currently beta1) for use on a Raspberry Pi running Raspberry Pi OS. Note: Beta, preliminary guide.

Guide on how to build Qt 6.2 (beta1) 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.

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 build stuff, 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. 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

Download Qt 6.2 base sources

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

Configure, build and install Qt 6.2 base

Extract the sources:

tar xf qtbase-everywhere-src-6.2.0-beta1.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 Qt will be run on the current device type.

To create a cmake toolchain file, tc.cmake, fire up your favorite editor. 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 is needed, remove CMAKE_TOOLCHAIN_FILE parameter if not used):

/opt/cmake/bin/cmake -G Ninja \
-DCMAKE_INSTALL_PREFIX=/opt/Qt/6.2.0-beta1-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-beta1

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 .
Keywords: 
Qt