Raspberry Pi Qt cross-compile: Unterschied zwischen den Versionen

Aus Nicki Wiki
Zur Navigation springen Zur Suche springen
Zeile 224: Zeile 224:
Einstellungen ⇒ Build & Run ⇒ Kits ⇒ Hinzufügen  
Einstellungen ⇒ Build & Run ⇒ Kits ⇒ Hinzufügen  
  Device type: Generic Linux Device
  Device type: Generic Linux Device
  Device: Welches erstellt wurde
  Device: Welches zuvor erstellt wurde
  Sysroot: /opt/qt5.15.2/sysroot
  Sysroot: /opt/qt5.15.2/sysroot
  Compiler: Welches erstellt wurde
  Compiler: Welches zuvor erstellt wurde
  Debugger: Welches erstellt wurde
  Debugger: Welches zuvor erstellt wurde
  Qt version: Welches erstellt wurde
  Qt version: Welches zuvor erstellt wurde
  Qt mkspec: leave empty
  Qt mkspec: bleibt leer


===Geräte===
===Geräte===

Version vom 10. Juni 2021, 17:43 Uhr

Raspberry Pi Qt cross-compile

Anleitung Cross-Compiling von Qt auf dem Raspberry PI 4 (RPI4) und ComputeModul 4 (CM4).
Eigenheiten beim RPI4 oder CM4 sind gekennzeichnet mit [RPI4] oder [CM4].

Vorbereitung RPI

Download letztes raspian-lite:

wget https://downloads.raspberrypi.org/raspios_lite_armhf_latest
wget https://downloads.raspberrypi.org/raspios_lite_armhf_latest -O "raspios.zip"
unzip raspios.zip

[CM4] Um mit dem CM4 arbeiten zu können muss USB und/oder SSH aktiviert werden. Für das kopieren von raspbian.img auf den eMMC wird das Tool rpiboot benötigt.

1. Image mounten: Linux - ISO-Image bearbeiten
2. SSH und USB aktivieren: Raspberry Pi CM4
3. Image auf CM4 kopieren: Raspberry Pi CM4

Kopieren des Image auf einem RPI mit SD-Karte:

dd if=raspbian.img of=/dev/sdb bs=1M    #raspbian.img ⇒ SD-Card
dd if=/dev/sdb of=raspbian.img bs=1M    #SD-Card ⇒ raspbian.img
sync                                    #leeren Zwischenspeicher BS

RPI starten, Dateisystem erweitern und Grafikspeicher erhöhen:

sudo raspi-config  # 1 System Options ⇒ S4 Hostname ⇒ cm4
                   # 4 Performance Options ⇒ GPU Memory ⇒ 128
                   # 6 Advanced Options ⇒ A1 Expand Filesystem
sudo reboot
sudo apt update && sudo apt upgrade -y
sudo apt autoremove # Wenn nötig

Installation Bibliotheken:

sudo vim /etc/apt/sources.list #uncomment the deb-src line
sudo apt update
sudo apt build-dep qt5-qmake -y
sudo apt build-dep libqt5gui5 -y
sudo apt build-dep libqt5webengine-data -y
sudo apt build-dep libqt5webkit5 -y
sudo apt install libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0 gdbserver -y

Zielverzeichnis anlegen:

sudo mkdir /usr/local/qt5.15
sudo chown pi:pi /usr/local/qt5.15

Zugriff RPI Datein

Variante 1: Netzwerk

Der RPI muss per ssh erreichbar sein.

Variante 2: mount image

Image von SD-Karte ziehen:

sudo mkdir /mnt/rasp-pi-rootfs
dd if=/dev/sdb of=raspbian.img bs=1M
fdisk -l raspian.img
sudo mount -o loop,offset=62914560 raspian.img /mnt/rasp-pi-rootfs   #Partition 2: 512 * 122880 = 62914560

Raspberry Pi mount image

Variante 3: mount SD-Card

Das mounten der SD-Karte erfolgt in den meisten Linux-Distributionen automatisch. Ansonsten:

sudo mount /dev/sdb2 /mnt/rasp-pi-rootfs

Vorbereitung HOST

Installation eines Ubuntu 20.04 (64Bit) (Minimal Installation) in einer VirtualBox.
Nach der BS installation Updates installiern:

sudo apt update && sudo apt upgrade -y
sudo apt install build-essential -y

Cross-Compile Toolchain

Arbeitsverzeichnis und Tools

Arbeitsverzeichnis anlegen und nötige Tools installieren:

sudo mkdir /opt/qt5.15.2 /opt/qt5.15.2/build /opt/qt5.15.2/tools
sudo chown -R user:user /opt
cd /opt/qt5.15.2

sysroot

Erstellen des sysroot Verzeichniss-Struktur und synchronisation mit raspian-image sysroot verzeichniss.

mkdir sysroot sysroot/usr sysroot/opt

Mit gemounterter SD-Karte:

rsync -avz /mnt/rasp-pi-rootfs/lib sysroot
rsync -avz /mnt/rasp-pi-rootfs/usr/include sysroot/usr
rsync -avz /mnt/rasp-pi-rootfs/usr/lib sysroot/usr
rsync -avz /mnt/rasp-pi-rootfs/opt/vc sysroot/opt

Oder übers Netzwerk:

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

Symlinks

Symlinks relativ anpassen:

wget https://raw.githubusercontent.com/Kukkimonsuta/rpi-buildqt/master/scripts/utils/sysroot-relativelinks.py
chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py sysroot #Bei Problemen: sudo ln -s /usr/bin/python3 /usr/bin/python

Qt Resourcen

Download Qt Resourcen [Pfad: /opt/qt5.15.2]

sudo wget http://download.qt.io/archive/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.tar.xz
sudo tar -vxf qt-everywhere-src-5.15.2.tar.xz

mkspec Datei für den Compiler modifizieren

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

Cross-Compiler

Download Linaro v7.4.1:

cd  /opt/qt5.15.2/tools
wget https://releases.linaro.org/components/toolchain/binaries/latest-7/arm-linux-gnueabihf/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz
tar -vxf gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz

Qt für RPI kompilieren:

cd /opt/qt5.15.2/build
../qt-everywhere-src-5.15.2/configure -release -opengl es2 -device linux-rasp-pi4-v3d-g++ -device-option CROSS_COMPILE=/opt/qt5.15.2/tools/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- -sysroot /opt/qt5.15.2/sysroot -prefix /usr/local/qt5.15 -extprefix /opt/qt5.15.2/qt5.15 -opensource -confirm-license -skip qtscript -skip qtwayland -skip qtwebengine -nomake tests -make libs -pkg-config -no-use-gold-linker -v -recheck

EGLFS-Bedingungen:

QPA backends:
  DirectFB ............................... no
  EGLFS .................................. yes  [Sollte YES sein]
  EGLFS details:
    EGLFS OpenWFD ........................ no
    EGLFS i.Mx6 .......................... no
    EGLFS i.Mx6 Wayland .................. no
    EGLFS RCAR ........................... no
    EGLFS EGLDevice ...................... yes  [Sollte YES sein]
    EGLFS GBM ............................ yes
    EGLFS VSP2 ........................... no
    EGLFS Mali ........................... no
    EGLFS Raspberry Pi ................... no   [Sollte NO sein]
    EGLFS X11 ............................ yes
  LinuxFB ................................ yes
  VNC .................................... yes

Wenn alles korrekt:

make -j2 #Anzahl verwendeter Kerne, hier 2 Kerne
make install
Option Erklärung
-release Debugging ausgeschaltet
-opengl es2 OpenGL ES 2.0 - Offene Grafik Bibliothek für eingebettete Systeme
-device linux-rasp-pi4-v3d-g++

RPI1:linux-rasp-pi-g++
RPI2:linux-rasp-pi2-g++
RPI3:linux-rasp-pi3-g++
RPI4:linux-rasp-pi4-v3d-g++
Optionen für bestimmtes Ziel-Gerät hier RPI4; Liste unterstützter Geräte qtbase/mkspecs/devices

-device-option CROSS_COMPILE=/opt/qt5.15.2/tools/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- Compiler
-sysroot /opt/qt5.15.2/sysroot sysroot Verzeichnis des Gerätes (RPI)
-prefix /usr/local/qt5.15' Qt Version für Qt-Creator
-opensource Die Lizenz wird auf GPL/LGPL gesetzt
-confirm-license Lizenzbedingungen zustimmen
-skip qtscript -skip qtwayland -skip qtwebengine Überspringen von Modulen (qtscript, qtwayland, qtwebengine)
-nomake tests Bauen von Tests aussschließen
-make libs Bauen von libs hinzufügen
-pkg-config Um Abhängigkeiten beim Cross-Compiling aufzulösen, erfordert PKG_CONFIG_PATH, PKG_CONFIG_PREFIX
-no-use-gold-linker Verwenden Sie nicht den GNU Gold Linker
-v Ausführliche Informationen über jeden Schritt des configure-Prozesses ausgeben
-recheck Bei einer neuen configuration wird das Build-Verzeichnis aktualisiert


Kompilierte Dateien auf RPI kopieren:

cd /opt/qt5.15.2

Mit gemounterter SD-Karte:

rsync -avz qt5.15 /mnt/rasp-pi-rootfs/usr/local

Oder übers Netzwerk:

rsync -avz --rsync-path="sudo rsync" qt5.15 pi@cm4:/usr/local/

Update RPI

RPI Bibliotheken updaten:

echo /usr/local/qt5.15/lib | sudo tee /etc/ld.so.conf.d/qt5.15.conf
sudo ldconfig

QT Creator

QT 5.15.2 installieren. Sollte Qt Creator nicht starten: /install_pfad/Qt/Tools/QtCreator/bin/qtcreator Fehler:

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.

Lösung:

export QT_DEBUG_PLUGINS=1

Folgefehler:

Cannot load library /home/user/Qt/Tools/QtCreator/lib/Qt/plugins/platforms/libqxcb.so

Lösung:

sudo apt install --reinstall libxcb-xinerama0

Qt Creater starten und unter Tools ⇒ Options... ⇒ Kits

Qt Versionen

Einstellungen ⇒ Kits ⇒ Qt Versionen ⇒ Hinzufügen

qmake location: /opt/qt5.15.2/qt5.15/bin/qmake

Compiler

Einstellungen ⇒ Kits ⇒ Compilers ⇒ Hinzufügen ⇒ GCC ⇒ C und C++

Compiler path C: /opt/qt5.15.2/tools/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
Compiler path C++: /opt/qt5.15.2/tools/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++

Debugger

Einstellungen ⇒ Debuggers ⇒ Hinzufügen

/opt/qt5.15.2/tools/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gdb

Kits

Einstellungen ⇒ Build & Run ⇒ Kits ⇒ Hinzufügen

Device type: Generic Linux Device
Device: Welches zuvor erstellt wurde
Sysroot: /opt/qt5.15.2/sysroot
Compiler: Welches zuvor erstellt wurde
Debugger: Welches zuvor erstellt wurde
Qt version: Welches zuvor erstellt wurde
Qt mkspec: bleibt leer

Geräte

Einstellungen ⇒ Geräte ⇒ Hinzufügen ⇒ Geberic Linux Device ⇒ IP, user, pass ⇒ Finish
RPI root per SSH erlauben:

sudo vim /etc/ssh/sshd_config
PermitRootLogin yes  #Auskommentieren und auf yes ändern
sudo reboot

bcm2835

Download

Auf RPI download bcm2835

wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.69.tar.gz

Installation

tar zxvf bcm2835-1.69.tar.gz
cd bcm2835-1.69
./configure
make
sudo make check
sudo make install

Nach Anpassungen an den .h und .c Datein:

cd bcm2835-1.69
make clean
./configure
make
sudo make check
sudo make install

Quellen

Raspberry Pi Beginners Guide
RaspberryPi2EGLFS
Cross-Compile QT 5.15.2 / Raspberry Pi 4
Qt 5.15 cross compile RPI4 auf Ubuntu 20 LTS
qt cross-compile configure-options