Cross-Compile between Qt5 and Raspberry Pi
: Crosscompile is the process of creating executable files on other platforms, Not on the platform which compiler runs
Environment - Laptop (Qt5): Ubuntu 20.04 / Raspberry Pi 4B: Raspbian Lite 64 bit
(If one of them is over Ubuntu 20, this proccess isn't working properly!!!!!!)
Add following line to /etc/apt/sources.list
deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
Update the System following command
When Update firmware, you need to choose stable version
sudo apt-get update
sudo apt-get dist-upgrade
sudo reboot
sudo rpi-update (firmware_version)
sudo reboot
If error occurs like "The following signatures couldn't be verified because the public key is not available: NO_PUBKEY (number)" -> Using command below
sudo -s
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys (number)
apt update
exit
Install some required 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
sudo mkdir /usr/local/qt5.15
sudo chown -R pi:pi /usr/local/qt5.15
Update Ubuntu and install some required package
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
Create directory structure
sudo mkdir ~ /Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4
sudo mkdir ~ /Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/build
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
Download Qt Resources and Modify mkspec to use our compiler
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
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
sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
Building Sysroot from Device
rsync -avzS --rsync-path=" rsync" --delete < pi_username> @< pi_ip_address> :/lib/ sysroot/lib
rsync -avzS --rsync-path=" rsync" --delete < pi_username> @< pi_ip_address> :/usr/include/ sysroot/usr/include
rsync -avzS --rsync-path=" rsync" --delete < pi_username> @< pi_ip_address> :/usr/lib/ sysroot/usr/lib
rsync -avzS --rsync-path=" rsync" --delete < pi_username> @< pi_ip_address> :/opt/vc/ sysroot/opt/vc
sudo apt install symlinks
symlinks -rc sysroot
Before compiling, we use aarch64 for device, so we need to add it to our directory
1. Make a directory named "linux-rasp-pi4-aarch64" in "Documents/Qt-CrossCompile-RaspberryPi/raspberrpy4/qt-everywhere-src-5.15.2/qtbase/mkspecs/devices/"
2. Download 2 files following upper url (qmake.conf, qplatformdefs.h) and add in "linux-rasp-pi4-aarch64" directory
If you finished previous process, following the command below
cd build
../qt-everywhere-src-5.15.2/configure -release -opengl es2 -eglfs -device linux-rasp-pi4-aarch64 -device-option CROSS_COMPILE=aarch64-linux-gnu- -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
If error occurs like "~ numeric_limits ~"
-> Add 3 lines top of ~/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/qt-everywhere-src-5.15.2/qtbase/src/corelib/global/qglobal.h
# ifdef __cplusplus
# include <limits>
# endif
Previous success without error, following command below
Setting Environment in Qt5
1. Select Tools -> External -> Configure
2. Select Devices -> Devices -> Add -> Remote Linux Device (Add your information of raspberry pi) -> Apply -> Test
3. Select Kits -> Qt Versions -> Add -> Open "Documents/Qt-CrossCompile-RaspberryPi/raspberrpy4/qt5.15/bin/qmake"
4. Select Kits -> Kits -> Add (Add your information) -> Apply
Name: Name of Kits you want to use
Run device type: Remote Linux Device
Run device: Select Device what you made in "Devices"
Compiler: C, C++ - arm 64bit (aarch64)
Qt version: Qt 5.15.2 (qt5.15)
If you finished setting and build process, using below command to send file to rpi
rsync -avz --rsync-path=" sudo rsync" (file_name) (pi_username)@ (pi_ip_address):(pi_location)