Cross Compiling Qt 5.10.1 for Raspberry Pi 3 on Ubuntu 18.04 LTS

Download raspbian stretch

$ wget https://downloads.raspberrypi.org/raspbian_latest
$ xzcat 2018-06-27-raspbian-stretch.img.xz | sudo dd of=/dev/mmcblk0 bs=4M

Install SD card, boot and configure wifi on raspbian
Edit /etc/apt/sources.lst and uncomment deb-src line

Update

$ sudo apt update
$ sudo apt upgrade
$ reboot

Second update after reboot

$ sudo rpi-update
$ reboot

# Install packages

$ sudo apt build-dep qt5-default qt5-qmake
$ sudo apt install libiconv-hook-dev libinput-dev libts-dev bluez libbluetooth-dev libgstreamer1.0-dev libegl1-mesa libegl1-mesa-dev

# Shutdown raspberry pi, remove SD card, make an image and mount

$ sudo dd if=/dev/sdc of=pidesktop.img bs=4M

# Find sector size and sector start of 2nd partition

$ fdisk -l pidesktop2.img
Disk pidesktop2.img: 7.5 GiB, 8068792320 bytes, 15759360 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xfa70646d

Device Boot Start End Sectors Size Id Type
pidesktop2.img1 8192 96663 88472 43.2M c W95 FAT32 (LBA)
pidesktop2.img2 98304 15759359 15661056 7.5G 83 Linux

Mount image as filesystem

$ sudo mkdir /mnt/pi.img
$ sudo mount ./pidesktop.img -o loop,offset=$((512*98304)) /mnt/pi.img/

Make symbolic links relative

$ wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py
$ sudo ./sysroot-relativelinks.py /mnt/pi.img/

# Download raspberry cross-compiler

$ git clone https://github.com/raspberrypi/tools.git

# Download QT 5.9.6 or 5.10.1 (5.11 needs a fully C++11 compliant compiler)

$ wget https://download.qt.io/official_releases/qt/5.9/5.9.6/single/qt-everywhere-opensource-src-5.9.6.tar.xz
$ wget https://download.qt.io/official_releases/qt/5.10/5.10.1/single/qt-everywhere-src-5.10.1.tar.xz

# Unzip QT

$ cd ~/raspberry
$ tar xJf qt-everywhere-opensource-src-5.9.6.tar.xz

# Create helper environment variables

$ export RPI_TOOLCHAIN=/home/hbucher/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-
$ export RPI_SYSROOT=/mnt/pi.img/

# Configure Qt

$ cd qt-everywhere-opensource-src-5.9.6
$ ./configure -opengl es2 -device linux-rasp-pi3-vc4-g++ -device-option CROSS_COMPILE=$RPI_TOOLCHAIN -sysroot $RPI_SYSROOT -opensource -confirm-license -reduce-exports -release -make libs -prefix /usr/local/qt5pi -no-use-gold-linker -skip qtscript -skip qtscript -skip qtwebengine -skip qtwebchannel -skip qtwebsockets -recheck-all

# Optional:

# -skip qtcharts -skip qt3d -skip qtdatavis3d -skip qtcanvas3d -skip qtgamepad -skip qtvirtualkeyboard
# -skip qtwayland -skip qtwebengine -skip qtwebchannel -skip qtwebglplugin -skip qtwebsockets

# Compile Qt

$ sudo make -j4
$ sudo make install

2 Replies to “Cross Compiling Qt 5.10.1 for Raspberry Pi 3 on Ubuntu 18.04 LTS”

  1. Hello Henry,
    thanks for this description.
    It works good! But I have some problems at the end:
    When I execute the command for
    #Configure Qt:
    ./configure -opengl es2 -device linux-rasp-pi3-vc4-g++ -device-option CROSS_COMPILE=$RPI_TOOLCHAIN -sysroot $RPI_SYSROOT -opensource -confirm-license -reduce-exports -release -make libs -prefix /usr/local/qt5pi -no-use-gold-linker -skip qtscript -skip qtscript -skip qtwebengine -skip qtwebchannel -skip qtwebsockets -recheck-all
    I get the error:
    You don’t seem to have ‘make’ or ‘gmake’ in your PATH.
    Do you have any idea what’s wrong?
    It would be fine if I get an answer soon by email.
    With kind regards
    Kurt