PC端:安装VM,并安装ubuntu20.04
树莓派:Raspberry Pi (32位)任何变体/模块 (Raspbian Buster/Bullseye) 注:64位没有测试,如有需要可自行测试
必须要再同一网络下,且内存足够大
1.1.做系统
–目前树莓派官网提供了一种安装系统的方式 详细请看树莓派系统烧录,文章后面的qt5.15安装一定要忽略!!
1.2.设置网络
连接上跟PC端相同的网络
1.3.设置SSH和GL (Fake KMS)
在 Raspberry Pi 终端上,键入:sudo raspi-config并且菜单应该会在您的终端上弹出。要启用 SSH,请转到:Interfacing Options-> SSH-> Yes,然后单击OK以启用它。最后选择Finish并退出
1.4. 启用开发源
sudo nano /etc/apt/sources.list
在 nano 文本编辑器中,通过从以下行中删除#字符来取消注释以下行:
deb-src http://raspbian.raspberrypi.org/raspbian/ main contrib non-free rpi
1.5.更新系统
sudo apt update
sudo apt dist-upgrade
1.6. 使用提升的权限启用 rsync
我们将使用该rsync命令在主机 PC/笔记本电脑和 Raspberry Pi 之间同步文件。对于其中一些文件,内部需要 root 权限(即 sudo)。
执行以下命令
echo "$USER ALL=NOPASSWD:$(which rsync)" | sudo tee --append /etc/sudoers
1.7.安装重要的开发包
sudo apt install build-essential cmake unzip pkg-config gfortran
sudo apt build-dep qt5-qmake libqt5gui5 libqt5webengine-data libqt5webkit5 libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0 gdbserver
sudo apt install libxcb-randr0-dev libxcb-xtest0-dev libxcb-shape0-dev libxcb-xkb-dev
1.8.附加包
# additional (multimedia) packages
sudo apt install libjpeg-dev libpng-dev libtiff-dev
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt install libxvidcore-dev libx264-dev openjdk-8-jre-headless
# audio packages
sudo apt install libopenal-data libsndio7.0 libopenal1 libopenal-dev pulseaudio
# bluetooth packages
sudo apt install bluez-tools
sudo apt install libbluetooth-dev
# gstreamer (multimedia) packages
sudo apt install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
1.8.创建QT部署目录
sudo mkdir /usr/local/qt5.15
sudo chown -R pi:pi /usr/local/qt5.15
1.9.设置重要的符号链接(重要)
我们的工具链需要很少的额外符号链接才能正常工作。因此,要可靠地创建所有必需的符号链接,我们需要下载SSymlinkerbash 脚本,如下所示:
wget 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
1.1.更新主机,安装必要软件
sudo apt update
sudo apt dist-upgrade
sudo apt install build-essential cmake unzip gfortran
sudo apt install gcc git bison python gperf pkg-config gdb-multiarch wget
sudo apt-get -y install gcc g++ gperf flex texinfo gawk bison openssl pigz libncurses-dev autoconf automake tar figlet
1.2.设置目录结构
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
cd ~/rpi-qt
1.3.下载并解压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 xfv qt-everywhere-src-5.15.2.tar.xz
1.4.修补QT源
们需要稍微修改源文件中的 mkspec 文件以允许我们使用我们的交叉编译器。我们将复制源文件中的现有目录,并修改目录名称和该目录中qmake.conf文件的内容以遵循我们编译器的名称。为此,请运行以下两个命令:
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
1.5.下载并解压预编译的交叉编译器
wget https://sourceforge.net/projects/raspberry-pi-cross-compilers/files/Raspberry%20Pi%20GCC%20Cross-Compiler%20Toolchains/Bullseye/GCC%2010.2.0/Raspberry%20Pi%203A%2B%2C%203B%2B%2C%204/cross-gcc-10.2.0-pi_3%2B.tar.gz/download
注意,这里我安装的是适用于树莓派4B的Bullseye操作系统,不同系统对应的交叉编译器不同
其他操作系统对应的编译器
Stretch(32-bit) OS 对应的是6.3.0
Buster(32-bit) OS 对应的是8.3.0
Bullseye(32-bit) OS 对应的是10.2.0
6.3.0-Raspberry Pi - 2 & 3 Model A/B
6.3.0-Raspberry Pi - 3 & 4 Model A+/B+ & Compute 3/3-lite/3+
8.3.0-Raspberry Pi - Zero/W/WH & 1 Model A/B/A+/B+
8.3.0-Raspberry Pi - 2 & 3 Model A/B
8.3.0-Raspberry Pi - 3 & 4 Model A+/B+ & Compute 3/3-lite/3+
10.2.0-Raspberry Pi - Zero/W/WH & 1 Model A/B/A+/B+
10.2.0-Raspberry Pi - 2 & 3 Model A/B
10.2.0-Raspberry Pi - 3 & 4 Model A+/B+ & Compute 3/3-lite/3+
解压
tar xf cross-gcc-*.tar.gz
1.6. 同步树莓派 sysroot(最重要)
cd ~/rpi-qt
rsync -avz --rsync-path="sudo rsync" --delete [email protected]:/lib sysroot
rsync -avz --rsync-path="sudo rsync" --delete [email protected]:/usr/include sysroot/usr
rsync -avz --rsync-path="sudo rsync" --delete [email protected]:/usr/lib sysroot/usr
rsync -avz --rsync-path="sudo rsync" --delete [email protected]:/opt/vc sysroot/opt
1.7.修复符号链接
wget https://raw.githubusercontent.com/abhiTronix/rpi_rootfs/master/scripts/sysroot-relativelinks.py
解压并运行
sudo chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py sysroot
1.8…配置QT Build
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
1.9.构建QT源码
make -j$(nproc)
make install
1.10将 QT 部署到树莓派
cd ~/rpi-qt
rsync -avz --rsync-path="sudo rsync" qt5.15 [email protected]:/usr/local
更新 Raspberry Pi 上的链接器
输入以下命令来更新设备,让链接器找到新的 QT 二进制文件:
echo /usr/local/qt5.15/lib | sudo tee /etc/ld.so.conf.d/qt5.15.conf
sudo ldconfig
传输文件
make nim && rsync -avz nim [email protected]:~/nim