Building Qt 6.2 for Raspberry Pi on Raspberry Pi OS
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:
- Downloading sources of Qt 6.2 components
- Checking the Qt 6.2 source package integrity
- Preparing the sources for building
- Installing all required dependencies
- Installing any optional dependencies
- Configuring the Qt 6.2 base build
- Compiling Qt 6.2 base
- Installing the Qt 6.2 base
And for any extra components it is basically a matter of:
- Install dependencies
- Extract sources
- 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:
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
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
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):
set(CMAKE_CROSSCOMPILING FALSE) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR armv6) set(TARGET armv6-linux-eabi)
set(CMAKE_CROSSCOMPILING FALSE) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR armv7) set(TARGET armv7-linux-eabi)
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 .