Thursday, December 21, 2017

Cross Compiling Qt for Raspberry Pi


These are notes on getting Qt 5.9.2 built on RPi cross compiling from a PC to avoid a long build time.

Target:  RPi model 2
Host: Ubuntu 16.04

1. (Target)
   Edit /etc/apt/sources.list and uncomment the deb-src line

   Install required libraries for target:

    sudo apt-get update      
    sudo apt-get build-dep qt4-x11
    sudo apt-get build-dep libqt5gui5
    sudo apt-get install libudev-dev libinput-dev \

                 libts-dev libxcb-xinerama0-dev  libxcb-xinerama0

   Setup target directories:

    sudo mkdir /usr/local/qt5pi
    sudo chown pi:pi /usr/local/qt5pi

 2. (Host)

   Setup working directory and get a toolchain

    mkdir ~/raspi
    cd ~/raspi
    git clone https:://github.com/raspberrypi/tools

    mkdir sysroot sysroot/usr sysroot/opt


   Libraries from RPi to Host:

    rsync -avz pi@rpi:/lib sysroot
    rsync -avz pi@rpi:/usr/include sysroot/usr
    rsync -avz pi@rpi:/usr/lib sysroot/usr
    rsync -avz pi@rpi:/opt/vc sysroot/opt


   Adjust symlinks to relative:

      wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py
      chmod +x sysroot-relativelinks.py
     ./sysroot-relativelinks.py sysroot


 3. (Host)
    Get opensource package for Qt (e.g qt-everywhere-opensource-src-5.9.2.tar.xz)

   The configure was tricky to setup, I got a clean build with:

    ./configure -release \
                -opengl es2 \
                -device linux-rasp-pi2-g++ \
                -device-option \
                CROSS_COMPILE=~/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- \
                -no-use-gold-linker \
                -sysroot ~/raspi/sysroot \
                -opensource \
                -confirm-license \
                -make libs -prefix /usr/local/qt5pi \
                -extprefix ~/raspi/qt5pi \
                -skip wayland \
                -skip qtwebengine \
                -hostprefix ~/raspi/qt5 -v


   Note the linux-rasp-pi2 which might need updating to linux-rasp-pi3 for newer models.  I dropped the qtwebengine and wayland to avoid some compile errors.

4. (Host) Deploy to Rpi

      rsync -avz qt5pi pi@raspberrypi.local:/usr/local

5. (Host) build an example app

     cd qtbase/examples/opengl/qopenglwidget
     ~/raspi/qt5/bin/qmake
     make

     scp qopenglwidget pi@raspberrypi.local:/home/pi

Sources

These were my starting points for this post:

https://wiki.qt.io/Native_Build_of_Qt5_on_a_Raspberry_Pi
https://wiki.qt.io/RaspberryPi2EGLFS

No comments: