출처: https://www.interelectronix.com/qt-raspberry-pi-4.html
QT ON THE RASPBERRY PI 4
Qt is often used to develop graphic interfaces. Qt contains C ++ libraries for creating graphical interfaces that can be compiled on various operating systems.
Since this compilation requires a lot of computing power, it is advisable for processors with relatively little power to carry out the development and compilation on a host computer and only then to load the finished application onto the target computer.
There are lots of instructions online for developing a Qt application for Raspberry Pi 3 and Pi 4 models.
Unfortunately, I couldn’t find one that worked flawlessly for the Raspberry Pi 4 and our needs.
These instructions are heavily based on https://github.com/abhiTronix/raspberry-pi-cross-compilers/blob/master/QT_build_instructions.md and are modified in some places so that it worked for me.
Version 5.15.2 is used for Qt, and I use an Ubuntu 20.0.4 LTS that is installed in vmware as the host computer for cross-compilation.
PREREQUITES
HARDWARE
Host [PC/Laptop]: Any x86/x86_64 AMD/Intel machine
Target [Raspberry Pi 4]: Raspberry Pi 4
SOFTWARE
Host: Any Linux machine (Ubuntu 20.04 LTS Tested)
Target: Raspberry Pi 4 Linux 32-bit OS (Raspbian Bullseye Lite tested)
NOTE
In the background the cross compile toolchains for Raspberry Pi from abhiTronix are used.
OTHERS
Storage and Time Requirements: The build directory takes around ~10GB space and about 2-5 hours to complete (based on dependencies & Host Machine Specifications).
Networking: Your Target Machine (Raspberry Pi) and Host Machine (where you cross-compiling) both MUST have Internet Access, and MUST be on SAME Network to follow these instructions.
PREPARING THE RASPBERRY PI 4
For the basic installation, we need a Raspberry Pi OS Lite operating system on the Pi 4. I used “2022-04-04-raspios-bullseye-armhf-lite.img.xz”.
Downloads and instructions on how to create an SD card with this can be found at https://www.raspberrypi.org/downloads/raspbian/.
After switching on the Pi 4, the configuration menu appears, where you can make various settings (e.g., host name, IP address, user, etc.). For our configuration, we need “SSH” activated.
INSTALL AND UPDATE SOFTWARE PACKAGES
- Add development sources in /etc/apt/sources.list with the following command:
|
1 2 3 |
[crayon-69352187e5ac4038755041 inline="true" ]sudo sed -i -e 's/\#deb-src/deb-src/g' /etc/apt/sources.list |
[/crayon]
- Then update the system with the following commands:
|
1 2 3 4 5 |
[crayon-69352187e5ad0548966345 inline="true" ]sudo apt-get update sudo apt-get -y dist-upgrade echo "$USER ALL=NOPASSWD:$(which rsync)" | sudo tee --append /etc/sudoers |
[/crayon]
- And then install the required Qt and development packages:
|
1 2 3 4 5 |
[crayon-69352187e5ada007514179 inline="true" ]sudo apt-get install -y build-essential cmake unzip pkg-config gfortran sudo apt-get build-dep -y qt5-qmake libqt5gui5 libqt5webengine-data libqt5webkit5 libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0 gdbserver sudo apt-get install -y libxcb-randr0-dev libxcb-xtest0-dev libxcb-shape0-dev libxcb-xkb-dev |
[/crayon]
- Install additional packages (depending on your needs):
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[crayon-69352187e5ae5984521171 inline="true" ]sudo apt install -y libjpeg-dev libpng-dev libtiff-dev sudo apt install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev sudo apt install -y libxvidcore-dev libx264-dev openjdk-8-jre-headless # audio packages sudo apt install -y libopenal-data libsndio7.0 libopenal1 libopenal-dev pulseaudio # bluetooth packages sudo apt install -y bluez-tools sudo apt install -y libbluetooth-dev # gstreamer (multimedia) packages sudo apt install -y libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-pulseaudio sudo apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev |
[/crayon]
- Then also create a directory for RaspberryQt:
|
1 2 3 4 |
[crayon-69352187e5af0148235404 inline="true" ]sudo mkdir /usr/local/qt5.15 sudo chown -R pi:pi /usr/local/qt5.15 |
[/crayon]
SETUP IMPORTANT SYMLINKS
Download symlinker tool and adjust symlinks.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[crayon-69352187e5afa643407883 inline="true" ]sudo wget -P ~/ https://raw.githubusercontent.com/abhiTronix/raspberry-pi-cross-compilers/master/utils/SSymlinker sudo chmod +x ~/SSymlinker ~/SSymlinker -s /usr/include/arm-linux-gnueabihf/asm -d /usr/include ~/SSymlinker -s /usr/include/arm-linux-gnueabihf/gnu -d /usr/include ~/SSymlinker -s /usr/include/arm-linux-gnueabihf/bits -d /usr/include ~/SSymlinker -s /usr/include/arm-linux-gnueabihf/sys -d /usr/include ~/SSymlinker -s /usr/include/arm-linux-gnueabihf/openssl -d /usr/include ~/SSymlinker -s /usr/lib/arm-linux-gnueabihf/crtn.o -d /usr/lib/crtn.o ~/SSymlinker -s /usr/lib/arm-linux-gnueabihf/crt1.o -d /usr/lib/crt1.o ~/SSymlinker -s /usr/lib/arm-linux-gnueabihf/crti.o -d /usr/lib/crti.o |
[/crayon]
PREPARING UBUNTU
UPDATE SOFTWARE AND INSTALL ADDITIONAL PACKAGES:
|
1 2 3 4 5 6 |
[crayon-69352187e5b05984392083 inline="true" ]sudo apt update sudo apt install -y build-essential cmake unzip gfortran sudo apt install -y gcc git bison python gperf pkg-config gdb-multiarch wget sudo apt-get -y install sshpass gcc g++ gperf flex texinfo gawk bison openssl pigz libncurses-dev autoconf automake tar figlet |
[/crayon]
PREPARE BUILD ENVIRONMENT
- Create folders:
|
1 2 3 4 5 6 7 8 9 10 |
[crayon-69352187e5b0f294525981 inline="true" ]sudo mkdir ~/rpi-qt sudo mkdir ~/rpi-qt/build sudo mkdir ~/rpi-qt/tools sudo mkdir ~/rpi-qt/sysroot sudo mkdir ~/rpi-qt/sysroot/usr sudo mkdir ~/rpi-qt/sysroot/opt sudo chown -R 1000:1000 ~/rpi-qt |
[/crayon]
- Download and extract Qt sources:
|
1 2 3 4 5 |
[crayon-69352187e5b18372978325 inline="true" ]sudo wget -P ~/rpi-qt http://download.qt.io/archive/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.tar.xz sudo tar xf ~/rpi-qt/qt-everywhere-src-5.15.2.tar.xz -C ~/rpi-qt/ sudo chown -R 1000:1000 ~/rpi-qt |
[/crayon]
- Patch QT sources.
|
1 2 3 4 5 |
[crayon-69352187e5b22198190570 inline="true" ]cp -R ~/rpi-qt/qt-everywhere-src-5.15.2/qtbase/mkspecs/linux-arm-gnueabi-g++ ~/rpi-qt/qt-everywhere-src-5.15.2/qtbase/mkspecs/linux-arm-gnueabihf-g++ sed -i -e 's/arm-linux-gnueabi-/arm-linux-gnueabihf-/g' ~/rpi-qt/qt-everywhere-src-5.15.2/qtbase/mkspecs/linux-arm-gnueabihf-g++/qmake.conf sed -i -e 's/\"main\"\: \"vc_dispmanx_display_open(0)\;\"/\"main\"\: \[\"vc_dispmanx_display_open(0)\;\"\, \"EGL_DISPMANX_WINDOW_T \*eglWindow \= new EGL_DISPMANX_WINDOW_T\;\"\]/g' ~/rpi-qt/qt-everywhere-src-5.15.2/qtbase/src/gui/configure.json |
[/crayon]
- Download and extract compiler:
|
1 2 3 4 5 |
[crayon-69352187e5b2d510143417 inline="true" ]sudo wget -P ~/rpi-qt/tools https://sourceforge.net/projects/raspberry-pi-cross-compilers/files/Raspberry%20Pi%20GCC%20Cross-Compiler%20Toolchains/Bullseye/GCC%2010.3.0/Raspberry%20Pi%203A%2B%2C%203B%2B%2C%204/cross-gcc-10.3.0-pi_3%2B.tar.gz sudo tar xf ~/rpi-qt/tools/cross-gcc-*.tar.gz -C ~/rpi-qt/tools/ sudo chown -R 1000:1000 ~/rpi-qt |
[/crayon]
- rsync files from raspberry: Use your values from your Raspberry for the variables raspberry_ip, raspberry_user and raspberry_pwd.
|
1 2 3 4 5 6 7 8 |
[crayon-69352187e5b37792921826 inline="true" ]raspberry_ip=192.168.2.108 raspberry_user=pi raspberry_pwd=raspberry touch ~/.ssh/known_hosts 위 touch 명령에서 에러가 발생한다면 ssh -T git@gitlab.com |
[/crayon]
|
1 2 3 |
[crayon-69352187e5b41859665869 inline="true" ]ssh-keyscan $raspberry_ip >> ~/.ssh/known_hosts sshpass -p "$raspberry_pwd" rsync -avz --rsync-path="sudo rsync" --delete "$raspberry_user"@"$raspberry_ip":/lib ~/rpi-qt/sysroot sshpass -p "$raspberry_pwd" rsync -avz --rsync-path="sudo rsync" --delete "$raspberry_user"@"$raspberry_ip":/usr/include ~/rpi-qt/sysroot/usr sshpass -p "$raspberry_pwd" rsync -avz --rsync-path="sudo rsync" --delete "$raspberry_user"@"$raspberry_ip":/usr/lib ~/rpi-qt/sysroot/usr |
[/crayon]
- Fix symbolic links:
|
1 2 3 4 5 |
[crayon-69352187e5b4b204286450 inline="true" ]wget -P ~/rpi-qt https://raw.githubusercontent.com/abhiTronix/rpi_rootfs/master/scripts/sysroot-relativelinks.py sudo chmod +x ~/rpi-qt/sysroot-relativelinks.py ~/rpi-qt/sysroot-relativelinks.py ~/rpi-qt/sysroot |
[/crayon]
- Configure Qt build:
|
1 2 3 4 5 |
[crayon-69352187e5b55691314192 inline="true" ]cd ~/rpi-qt/build CROSS_COMPILER_LOCATION="$HOME"/rpi-qt/tools/cross-pi-gcc-* ../qt-everywhere-src-5.15.2/configure -release -opengl es2 -eglfs -device linux-rasp-pi4-v3d-g++ -device-option CROSS_COMPILE=$(echo $CROSS_COMPILER_LOCATION)/bin/arm-linux-gnueabihf- -sysroot ~/rpi-qt/sysroot/ -prefix /usr/local/qt5.15 -extprefix ~/rpi-qt/qt5.15 -opensource -confirm-license -skip qtscript -skip qtwayland -skip qtwebengine -nomake tests -make libs -pkg-config -no-use-gold-linker -v -recheck -L$HOME/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf -I$HOME/rpi-qt/sysroot/usr/include/arm-linux-gnueabihf |
[/crayon]
- Build Qt:
|
1 2 3 4 |
[crayon-69352187e5b5f866030137 inline="true" ]make -j$(nproc) make install |
[/crayon]
- rsync Qt binaries to Raspberry:
|
1 2 3 |
[crayon-69352187e5b69204530898 inline="true" ]sshpass -p "$raspberry_pwd" rsync -avz --rsync-path="sudo rsync" ~/rpi-qt/qt5.15 "$raspberry_user"@"$raspberry_ip":/usr/local |
[/crayon]
FINAL STEP ON TARGET MACHINE (RASPBERRY PI)
- Update linker on Raspberry Pi
Enter the following command on the Raspberry Pi to update the device letting the linker to find the new QT binary files:
|
1 2 3 4 |
[crayon-69352187e5b74678573802 inline="true" ]echo /usr/local/qt5.15/lib | sudo tee /etc/ld.so.conf.d/qt5.15.conf sudo ldconfig |
[/crayon]
INSTALLING QT CREATOR
|
1 2 3 4 5 |
[crayon-69352187e5b7e393947000 inline="true" ]sudo apt update sudo apt install build-essential sudo apt install qtcreator |
CONFIGURE QT CREATOR FOR CROSS COMPILING
Read the blog Configuring Qt-Creator on Ubuntu 20 Lts for cross-compilation for including the compiled binaries (folder ~/rpi-qt/qt5.15) in Qt Creator.