Skip to content

Instantly share code, notes, and snippets.

@midoriiro
Last active February 8, 2024 18:00
Show Gist options
  • Save midoriiro/d8966ce378c283b94f233fdb71f19ee6 to your computer and use it in GitHub Desktop.
Save midoriiro/d8966ce378c283b94f233fdb71f19ee6 to your computer and use it in GitHub Desktop.
Cross-compile Qt-5.11.3 from Linux to Raspberry PI 3 B+

How to build Qt from source for the Raspberry PI platform

References

Linux references guides:

https://fecub.wordpress.com/2018/01/15/compile-qt-for-raspberry-pi/

http://www.tal.org/tutorials/building-qt-510-raspberry-pi-debian-stretch

Qt Creator configuration reference guide:

https://stackoverflow.com/questions/32027057/qt-creator-proper-setup-for-cross-compilation-and-remote-deployment-for-the-rasp

Step by step

[rpi] Raspbian 9 (stretch)

$ 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 libudev-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0

Additional dependencies

Bluetooth
$ apt-get install bluez libbluetooth-dev
Gstreamer
$ 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
Alsa
$ apt-get install libasound2-dev
Pulseaudio
$ apt-get install pulseaudio libpulse-dev
Sql
$ apt-get install libpq-dev libmariadbclient-dev
Print
$ apt-get install libcups2-dev
Wayland
$ apt-get install libwayland-dev
X11
$ apt-get install libx11-dev libxcb1-dev libxkbcommon-x11-dev libx11-xcb-dev libxext-dev
Accessibility
$ apt-get install libatspi-dev

to build specific module see the Qt doc to know dependencies to install

Fix the EGL/GLES libraries

$ sudo mv /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0 /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0_backup
$ sudo mv /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0 /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0_backup
$ sudo ln -s /opt/vc/lib/libEGL.so /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0
$ sudo ln -s /opt/vc/lib/libGLESv2.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0
$ sudo ln -s /opt/vc/lib/libEGL.so /opt/vc/lib/libEGL.so.1
$ sudo ln -s /opt/vc/lib/libGLESv2.so /opt/vc/lib/libGLESv2.so.2

[host] Debian 9 (stretch)

$ cd
$ mkdir ~/rpi
$ cd rpi
$ mkdir sysroot sysroot/usr sysroot/opt qt-build qt-build-local

Paste the following bash script into a named file rsync.sh (change port, ip address and remote user accordingly to your configuration)

#!/bin/bash
rsync -avz -e "ssh -p 13377" pi@192.168.43.71:/lib sysroot
rsync -avz -e "ssh -p 13377" pi@192.168.43.71:/usr/include sysroot/usr
rsync -avz -e "ssh -p 13377" pi@192.168.43.71:/usr/lib sysroot/usr                                                                                                                                                                                                             
rsync -avz -e "ssh -p 13377" pi@192.168.43.71:/opt/vc sysroot/opt                                                                                                                                                                                                              
rsync -avz -e "ssh -p 13377" pi@192.168.43.71:/usr/local/include sysroot/usr/local                                                                                                                                                                                             
rsync -avz -e "ssh -p 13377" pi@192.168.43.71:/usr/local/lib sysroot/usr/local 
$ ./rsync.sh
$ git clone https://github.com/raspberrypi/tools
$ wget https://raw.githubusercontent.com/riscv/riscv-poky/priv-1.10/scripts/sysroot-relativelinks.py
$ chmod +x sysroot-relativelinks.py
$ ./sysroot-relativelinks.py sysroot

/!\ This guide has only been tested with Qt version 5.11.3

$ wget http://download.qt.io/official_releases/qt/5.11/5.11.3/single/qt-everywhere-src-5.11.3.tar.xz
$ tar xf qt-everywhere-src-5.11.3.tar.xz
$ mv qt-everywhere-src-5.11.3 qt-src

Paste the following bash script into a named file configure.sh (configure Qt to be cross compiled)

#!/bin/bash
~/rpi/qt-src/configure \
        -release \
        -platform linux-g++ \
        -device linux-rasp-pi3-g++ \
        -device-option CROSS_COMPILE=~/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- \
        -sysroot ~/rpi/sysroot \
        -opensource \
        -confirm-license \
        -prefix /usr/local/qt5 \
        -extprefix ~/rpi/qt-build/qt5pi \
        -hostprefix ~/rpi/qt-build/qt5 \
        -v \
        -no-use-gold-linker \
        -nomake examples \
        -nomake tests \
        -no-compile-examples \
        -skip qtscript

Paste the following bash script into a named file configure-local.sh (configure Qt to be compiled natively)

#!/bin/bash
~/rpi/qt-src/configure \
        -release \
        -platform linux-g++ \
        -opensource \
        -confirm-license \
        -prefix /usr/local/qt5 \
        -extprefix ~/rpi/qt-build-local/qt5 \
        -hostprefix ~/rpi/qt-build-local/qt5 \
        -v \
	-nomake examples \
        -nomake tests \
	-no-compile-examples \1
        -skip qtscript

Cross-compile Qt

[host]

$ cd qt-build
$ ./../configure.sh
$ make -j N # N = number of logical CPU core
$ make -j N install

Find a way to transfert the Qt folder ~/rpi/qt-build/qt5pi to the remote path /usr/local/qt5, may be with the scp command ?

[rpi] fix qt5 libraries

$ mkdir ~/tmpsymlink
$ cd ~/tmpsymlink
$ ln -s /usr/local/qt5/lib/libQt5*.so.5.11.3 ~/tmpsymlink
$ rename 's/.11.3//;' *
$ mv * /usr/local/qt5/lib/
$ cd
$ rm -R tmpsymlink/

add to /etc/bash.bashrc the following lines

export PATH=$PATH:/usr/local/qt5/bin

Compile Qt natively

$ cd qt-build-local
$ ./../configure-local.sh
$ make -j N # N = number of logical CPU core
$ make -j N install

Configure Qt Creator to handle the cross compiled Qt kit:

/!\ Qt Creator is not provided by the cross-compiled build. Download Qt for linux platform and install Qt Creator from https://www.qt.io/download

/!\ Based on Qt Creator 4.8.0

Go to Tools -> Options -> Devices
    Add
        Generic Linux Device
        Enter IP address, user & password
        Finish
Go to Tools -> Options -> Kits -> Compilers
    Add
        GCC
        Compiler path: ~/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++
Go to Tools -> Options -> Kits -> Debuggers
    Add
        ~/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gdb
Go to Tools -> Options -> Kits -> Qt Versions
    Check if an entry with ~/rpi/qt5/bin/qmake shows up. If not, add it.
Go to Tools -> Options -> Kits -> Kits
    Kits
        Add
        Generic Linux Device
        Device: the one we just created
        Sysroot: ~/rpi/sysroot
        Compiler: the one we just created
        Debugger: the one we just created
        Qt version: the one we saw under Qt Versions
        Qt mkspec: leave empty

Try to compile an example.

Happy coding !

Avoid unreadable QML controls

add to /etc/bash.bashrc the following lines for a display screen with resolution of 1920*1080 (for other resolution do a simple conversion from pixel to millimeter)

export QT_QPA_EGLFS_PHYSICAL_WIDTH=508
export QT_QPA_EGLFS_PHYSICAL_HEIGHT=285.75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment