Introduction
This is a guide for cross-compiling Qt 5.15.2 for Raspberry Pi 4 and installing it on Compute Module 4. It is an update to my blog post Qt on the Raspberry Pi 4, with the difference that this time I am using Raspberry Pi OS Lite (download here: https://www.raspberrypi.org/software/operating-systems/), Qt Version 5.15.2, and Ubuntu 20 LTS in a virtual machine as a cross-compile computer .
Sources
In addition to my old blog post (see above), I have also used the following sources:
- from Uvindu Wijesinghe: https://github.com/UvinduW/Cross-Compiling-Qt-for-Raspberry-Pi-4
Raspberry Pi OS Lite
Install Raspberry Pi OS Lite on a Raspberry Pi 4, or on a Raspberry Compute Module 4, as described in my blog post Installing Raspberry Pi OS on the Raspberry Compute Module 4.
Qt 5.15.2 on Ubuntu 20 LTS
After the Raspberry Pi OS has been installed on the Compute Module and the Raspberry starts again from the eMMC storage, it is time to install the required software on the Raspberry and on the Ubuntu machine.
Raspberry Compute Module 4
The steps shown below should also work on a "normal" Raspberry Pi 4.
After switching on the Pi 4, call up the configuration menu.
sudo raspi-config
For our configuration, we need "SSH" and "GL (Fake KMS)" – see the following two screenshots.


- Then enter development sources in /etc/apt/sources.list. To do so, add the following line:
deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
- Then bring the system up to date using the following commands:
sudo apt-get update
sudo apt-get dist-upgrade
sudo reboot
sudo rpi-update
sudo reboot
- And then install the required Qt and development packages:
sudo apt-get build-dep qt5-qmake
sudo apt-get build-dep libqt5gui5
sudo apt-get build-dep libqt5webengine-data
sudo apt-get build-dep libqt5webkit5
sudo apt-get install libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0 gdbserver
- Then create another directory for RaspberryQt:
sudo mkdir /usr/local/qt5.15
sudo chown -R pi:pi /usr/local/qt5.15
Ubuntu machine
A PC or a virtual machine with Ubuntu 20 LTS installed is required.
First of all, bring Ubuntu up to date and install some required libraries:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install gcc git bison python gperf pkg-config gdb-multiarch
sudo apt install build-essential
Then – if it doesn't already exist – generate an ssh key and install it on the Raspberry so that you do not get a password request and have to enter the user name and password every time you do a rsync. There are enough instructions for this online, so I will save myself a detailed description here.
Creating the directory structure for the Raspberry libraries
For the required files, I create the following directory structure under Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4:
sudo mkdir ~/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4
sudo mkdir ~/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/build
sudo mkdir ~/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/tools
sudo mkdir ~/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot
sudo mkdir ~/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr
sudo mkdir ~/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/opt
sudo chown -R 1000:1000 ~/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4
cd ~/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4
Downloading the Qt resources
We download the Qt resources and unzip them in the raspberrypi4 directory:
sudo wget http://download.qt.io/archive/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.tar.xz
sudo tar xfv qt-everywhere-src-5.15.2.tar.xz
Now we have to modify the mkspec file a little so that we can use it with our compiler. To do this, execute the following commands:
cp -R qt-everywhere-src-5.15.2/qtbase/mkspecs/linux-arm-gnueabi-g++ qt-everywhere-src-5.15.2/qtbase/mkspecs/linux-arm-gnueabihf-g++
sed -i -e 's/arm-linux-gnueabi-/arm-linux-gnueabihf-/g' qt-everywhere-src-5.15.2/qtbase/mkspecs/linux-arm-gnueabihf-g++/qmake.conf
Downloading the cross-compiler
I use a Linaro version 7.4.1 as the cross-compiler. To do this, go to the Tools directory and download and unzip the compiler:
cd tools
sudo wget https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/arm-linux-gnueabihf/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz
tar xfv gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz
Rsync for the Raspberry libraries
Now we also need the original Raspberry Pi libraries, which we copy into the Ubuntu directories using rsync:
cd ..
rsync -avz --rsync-path="sudo rsync" --delete [email protected]:/lib sysroot/
rsync -avz --rsync-path="sudo rsync" --delete [email protected]:/usr/include sysroot/usr/
rsync -avz --rsync-path="sudo rsync" --delete [email protected]:/usr/lib sysroot/usr/
rsync -avz --rsync-path="sudo rsync" --delete [email protected]:/opt/vc sysroot/opt/
Now we still have to clean up the symbolic links that were copied by the rsync so that they point to the correct original files. There is a small Python script to download for this:
wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py
Then make the script executable and call it:
sudo chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py sysroot
Compiling Qt
Now we can configure the build and then compile it.
cd build
../qt-everywhere-src-5.15.2/configure -release -opengl es2 -eglfs -device linux-rasp-pi4-v3d-g++ -device-option CROSS_COMPILE=~/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/tools/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- -sysroot ~/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot -prefix /usr/local/qt5.15 -extprefix ~/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/qt5.15 -opensource -confirm-license -skip qtscript -skip qtwayland -skip qtwebengine -nomake tests -make libs -pkg-config -no-use-gold-linker -v -recheck
After a few minutes, the script should be complete and the following EGLFS conditions should be set/not set, as the case may be.
QPA backends:
DirectFB ............................... no
EGLFS .................................. yes [SHOULD BE YES]
EGLFS details:
EGLFS OpenWFD ........................ no
EGLFS i.Mx6 .......................... no
EGLFS i.Mx6 Wayland .................. no
EGLFS RCAR ........................... no
EGLFS EGLDevice ...................... yes [SHOULD BE YES]
EGLFS GBM ............................ yes
EGLFS VSP2 ........................... no
EGLFS Mali ........................... no
EGLFS Raspberry Pi ................... no [SHOULD BE NO]
EGLFS X11 ............................ yes
LinuxFB ................................ yes
VNC .................................... yes
If this is not the case or if you get any other error messages, please investigate and rectify. If you want to run the configuration script again with changed variables, then please be sure to delete the content of the build directory beforehand.
If everything is OK, then execute the commands "make" and "make install".
make -j4
make install
Installing the compiled files on the Raspberry
If the compilation was successful, the compiled files – they are located in the qt5.15 directory – can be copied to the Raspberry Pi. We do this using the rsync command again.
rsync -avz --rsync-path="sudo rsync" qt5.15 [email protected]:/usr/local/
QtCreator configuration
In the nextblog post, I explain how to use QtCreator for deployment with the compiled libraries.