Cross-Compile QT6.5.0 for X3Pi

1 . 交叉编译Qt6.5.0

1.1 使用源码编译cmake

sudo apt install libssl-dev
git clone https://github.com/Kitware/CMake.git
cd CMake
./bootstrap && make && sudo make install

1.2 安装 Node.js (14或以上)和 npm

1.3 Host安装依赖包和编译Qt

1.3.1 依赖包

# 安装依赖包
sudo apt-get install make build-essential libclang-dev ninja-build gcc git bison python3 gperf pkg-config libfontconfig1-dev libfreetype6-dev libx11-dev libx11-xcb-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libxcb-glx0-dev libxcb-keysyms1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync-dev libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-util-dev libxcb-xinerama0-dev libxcb-xkb-dev libxkbcommon-dev libxkbcommon-x11-dev libatspi2.0-dev libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev

# Qt TextToSpeech
sudo apt install libspeechd-dev flite1-dev libasound2-dev

# multimedia
sudo apt install libavcodec-dev libavformat-dev libavfilter-dev libavdevice-dev

# bluetooth
sudo apt install libpcsclite-dev libbluetooth-dev

#/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory
sudo apt-get install libc6-dev-i386 

1.3.2 cmake

cmake ../qt-everywhere-src-6.5.0/ -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DQT_BUILD_EXAMPLES=OFF \
-DQT_BUILD_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX=/home/am/installed/qt6-host \
--log-level=VERBOSE

1.3.3 编译和安装

cmake --build . --parallel 8
cmake --install .

1.4 Target安装依赖包和编译Qt

1.4.1 升级系统

sudo apt update
sudo apt upgrade
sudo reboot

1.4.2 查找指定文件属于哪个包

dpkg-query --search /usr/include/brotli/decode.h

1.4.3 pkg-config检查dbus-1是否安装

pkg-config --libs --cflags dbus-1

1.4.4 安装裁剪完整依赖包

sudo apt install -y libboost1.71-all-dev libudev-dev libinput-dev libts-dev \
libmtdev-dev libjpeg-dev libfontconfig1-dev libssl-dev libdbus-1-dev \
libglib2.0-dev libpulse-dev libsnappy-dev libnss3-dev flex bison libxslt-dev \
ruby gperf libbz2-dev libcups2-dev libfreetype6-dev libicu-dev libsqlite3-dev \
libavcodec-dev libavformat-dev libavfilter-dev libavdevice-dev  libswscale-dev \
libspeechd-dev flite1-dev libasound2-dev libpcsclite-dev libbluetooth-dev \
libxcursor-dev libxcomposite-dev libaudio-dev rsync libbrotli-dev libxrandr-dev

1.4.5 安装完整依赖包

# 安装依赖包1
sudo apt-get install libboost-all-dev libudev-dev libinput-dev libts-dev libmtdev-dev libjpeg-dev libfontconfig1-dev libssl-dev libdbus-1-dev libglib2.0-dev libxkbcommon-dev libegl1-mesa-dev libgbm-dev libgles2-mesa-dev mesa-common-dev libasound2-dev libpulse-dev gstreamer1.0-omx libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev  gstreamer1.0-alsa libvpx-dev libsrtp2-dev libsnappy-dev libnss3-dev "^libxcb.*" flex bison libxslt-dev ruby gperf libbz2-dev libcups2-dev libatkmm-1.6-dev libxi6 libxcomposite1 libfreetype6-dev libicu-dev libsqlite3-dev libxslt1-dev

# 安装依赖包2
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libx11-dev freetds-dev libsqlite3-dev libpq-dev libiodbc2-dev firebird-dev libgst-dev libxext-dev libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync1 libxcb-sync-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-glx0-dev libxi-dev libdrm-dev libxcb-xinerama0 libxcb-xinerama0-dev libatspi2.0-dev libxcursor-dev libxcomposite-dev libxdamage-dev libxss-dev libxtst-dev libpci-dev libcap-dev libxrandr-dev libdirectfb-dev libaudio-dev libxkbcommon-x11-dev

# 安装TTS Engine
sudo apt install libspeechd-dev flite pulseaudio libpulse-dev osspd
# 安装rsync用于与Host执行rsync
sudo apt install -y rsync
# 删除不需要的包
sudo apt remove libzstd-dev libharfbuzz-bin libharfbuzz-dev

1.4.6 把sysroot从Target同步到Host

  • 同步示例:
rsync -avz --rsync-path="sudo rsync" --delete pi@192.168.1.7:/usr/lib sysroot/usr
  • The –rsync-path=“sudo rsync” option allows us to access files on the target system that may require elevated rights.
  • The –delete option will delete any files from our host system if they have also been deleted on the target system.
# create sysroot
mkdir /home/am/nfs/sysroot; mkdir /home/am/nfs/sysroot/usr
cd /home/am/nfs

#  rsync system files from target to PC
rsync -avz root@192.168.1.12:/lib sysroot
rsync -avz root@192.168.1.12:/usr/include sysroot/usr
rsync -avz root@192.168.1.12:/usr/lib sysroot/usr
# or
rsync -avz --rsync-path="sudo rsync"  root@192.168.1.12:/lib sysroot
rsync -avz --rsync-path="sudo rsync"  root@192.168.1.12:/usr/include sysroot/usr
rsync -avz --rsync-path="sudo rsync"  root@192.168.1.12:/usr/lib sysroot/usr
  • 同步符号链接
sudo apt install symlinks
symlinks -rc sysroot

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

1.4.7 cmake

cmake ../qt-everywhere-src-6.5.0/ -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DQT_BUILD_EXAMPLES=OFF \
-DQT_BUILD_TESTS=OFF \
-DQT_HOST_PATH=$HOME/installed/qt6-host \
-DCMAKE_STAGING_PREFIX=$HOME/installed/qt6-x3 \
-DCMAKE_INSTALL_PREFIX=/usr/local/qt6-x3 \
-DCMAKE_TOOLCHAIN_FILE=$HOME/tools/toolchain.cmake \
-DQT_QMAKE_TARGET_MKSPEC=linux-aarch64-gnu-g++ \
-DFEATURE_optimize_size=ON \
-DINPUT_opengl=no \
-DFEATURE_linuxfb=ON \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_qtwayland=OFF \
-DBUILD_qtwebchannel=OFF \
-DBUILD_qtwebengine=OFF \
-DBUILD_qtwebview=OFF \
-DBUILD_qtdoc=OFF

1.4.8 编译和安装

cmake --build . --parallel 8
cmake --install .

1.4.9 布署Qt到target 板

  • 拷贝Qt安装文件
cd /home/am/install
rsync -avz --rsync-path="sudo rsync" qt6 root@192.168.1.12:/usr/local
  • 更新Linker (以让Targer linker找到Qt库文件)
echo /usr/local/qt5.15.9/lib | sudo tee /etc/ld.so.conf.d/qt5.15.9.conf
sudo ldconfig
  • 修正dbus链接
cd /home/am/installed/sysroot/usr/lib/aarch64-linux-gnu
rm libdbus-1.so
ln -s libdbus-1.so.3.19.11 libdbus-1.so

1.5 编译和运行Qt应用

  • 编译
$ cd /tools/qt-everywhere-src-6.5.0/qtbase/examples/widgets/widgets/analogclock/
$ mkdir build; cd build;
$ qt-cmake ..

### CMake is configuring here. After it is done without any error, we can proceed to build and install it
$ cmake --build . --parallel 4
# or 
$ make

$ cmake --install .
  • 拷贝到板子上运行
$ scp -r analogclock <pi_username>@<pi_ip_address>:/home/pi
$ ssh <pi_username>@<pi_ip_address>

# set running environment
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/qt6/lib
$ export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0:size=1920x1080:mmsize=1920x1080:offset=0x0:nographicsmodeswitch=0

# 解决2个Mouse Cursors, disable lightdm
$ sudo systemctl disable lightdm
# 恢复lightdm
$ sudo dpkg-reconfigure lightdm

$ cd /home/pi
$ ./analogclock

2. 在QtCreator中设置交叉编译环境

2.1 运行

  • 在目标板上找不到工具链中的.so
sudo vim /etc/ld.so.conf.d/toolchain.conf
# 把找不到.so所在的路径copy到上面的toolchain.conf中
sudo ldconfig
  • 设置 QT_QPA_PLATFORM
#错误信息:
#qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
#This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
#Available platform plugins are: linuxfb, minimal, offscreen, vnc.
export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0:size=1920x1080:mmsize=1920x1080:offset=0x0:nographicsmodeswitch=0

3. 修改系统配置

3.1 修改静态IP配置

  • 静态网络配置保存在/etc/network/interfaces文件中,通过修改address、netmask、gateway等字段,可完成对静态IP配置的修改
sudo vim /etc/network/interfaces
  • 配置文件内容如下:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto eth0
iface eth0 inet static
    address 192.168.3.100
    netmask 255.255.255.0
    gateway 192.168.3.1 
    metric 700
  • 修改完成后,命令行输入以下命令让配置生效
sudo restart_network

3.2 修改DHCP配置

  • DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)通常被应用在大型的局域网络环境中,主要作用是集中的管理、分配IP地址,使网络环境中的主机动态的获得IP地址、Gateway地址、DNS服务器地址等信息,并能够提升地址的使用率。开发板的DHCP网络配置保存在/etc/network/interfaces文件,通过修改eth0相关配置,可完成对DHCP模式的修改
sudo vim /etc/network/interfaces
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
    metric 700
  • 修改完成后,命令行输入以下命令让配置生效
sudo restart_network

3.3 修改MAC地址配置

  • 如需修改开发板默认MAC地址,可通过在/etc/network/interfaces文件中增加pre-up配置信息,指定用户需要的MAC地址
sudo vim /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto eth0
iface eth0 inet static
    address 192.168.3.100
    netmask 255.255.255.0
    gateway 192.168.3.1 
    pre-up ifconfig eth0 hw ether 00:11:22:9f:51:27
  • 修改完成后,命令行输入以下命令让配置生效
sudo restart_network

3.4 使用命令连接WiFi

  • 扫描热点
sudo nmcli device wifi rescan
  • 列出扫描到的热点
sudo nmcli device wifi list
  • 连接WiFi
sudo wifi_connect "SSID" "PASSWD"

3.5 自启动配置

  • 通过在sudo vim /etc/rc.local文件末尾添加命令,可实现开机自启动功能,例如:
#!/bin/bash -e
# 
# rc.local
#re
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

#!/bin/sh

chmod a=rx,u+ws /usr/bin/sudo
chown sunrise:sunrise /home/sunrise

which "hrut_count" >/dev/null 2>&1
if [ $? -eq 0 ]; then
        hrut_count 0
fi

# Insert what you need
# set usb to host mode
echo host > /sys/devices/platform/soc/b2000000.usb/b2000000.dwc3/role
# set running environment
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/qt6-x3/lib
$ export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0:size=1920x1080:mmsize=1920x1080:offset=0x0:nographicsmodeswitch=0

3.6 查看芯片运行状态

sudo hrut_somstatus

3.7 Ubuntu系统启动顺序

  • 第一步:
init /etc/inittab
  • 第二步:启动相应的脚本,并且打开终端
rc.sysinit
rc.d(里面的脚本)
rc.local
  • 第三步:启动login登录界面 login
  • 第四步:在用户登录的时候执行sh脚本的顺序,每次登录的时候都会完全执行的
/etc/profile.d/file
/etc/profile
/etc/bashrc
/root/.bashrc
/root/.bash_profile

4. 常用工具

4.1 Target与电脑端文件传输

  • 拷贝单文件 local_file 到target /userdata目录下:
scp local_file root@192.168.3.100:/userdata/
  • 拷贝整个文件夹 local_folder 到target /userdata目录下:
scp -r local_folder root@192.168.3.100:/userdata/

4.2 IAR调试信息

  • 查看IAR调试信息:
cat /sys/kernel/debug/iar
  • 输出内容如下:
    在这里插入图片描述

4.4 linuxfb

  • This linuxfb plugin writes directly to the framebuffer. Only software-rendered content is supported. Note that on some setups the display performance is expected to be limited.
  • The linuxfb plugin allows specifying additional settings by passing them in the QT_QPA_PLATFORM environment variable or -platform command-line option. For example, QT_QPA_PLATFORM=linuxfb:fb=/dev/fb1 specifies that the framebuffer device /dev/fb1 must be used instead of the default fb0. Multiple settings can be specified by separating them with a colon.
  • fb=/dev/fbN - Specifies the framebuffer devices. On multiple display setups this typically allows running the application on different displays. For the time being there is no way to use multiple framebuffers from one Qt application.
  • size=<width>x<height> - Specifies the screen size in pixels. The plugin tries to query the display dimensions, both physical and logical, from the framebuffer device. This may not always lead to proper results however, and therefore it may become necessary to explicitly specify the values.
  • mmsize=<width>x<height> - Physical width and height in millimeters.
  • offset=<width>x<height> - Offset in pixels specifying the top-left corner of the screen. The default position is at (0, 0).
  • nographicsmodeswitch - Do not switch the virtual terminal to graphics mode (KD_GRAPHICS). In addition to switching to graphics mode, the blinking cursor and screen blanking are normally disabled too. When this parameter is set, these are also skipped.
  • tty=/dev/ttyN - Overrides the virtual console. Only used when nographicsmodeswitch is not set.

4.5 Target Error

4.5.1 非UTF-8

root@ubuntu:/userdata# ./HelloQt6
Detected locale "C" with character encoding "ANSI_X3.4-1968", which is not UTF-8.
Qt depends on a UTF-8 locale, and has switched to "C.UTF-8" instead.
If this causes problems, reconfigure your locale. See the locale(1) manual
for more information.
  • 解决方案
# 查看支持的编码格式
locale -a
# 解决此问题
export LC_ALL=en_US.UTF-8

参考链接

- [参考1](https://github.com/UvinduW/Cross-Compiling-Qt-for-Raspberry-Pi-4)
- [参考2](https://mechatronicsblog.com/cross-compile-and-deploy-qt-5-12-for-raspberry-pi/)
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值