主机系统:Ubuntu16.04
树莓派3B+系统:Raspbian
/etc/apt/sources.list中的编辑源列表,并取消注释deb-src行
sudo nano /etc/apt/sources.list
更新,下载需要的开发包
sudo apt-get build-dep qt4-x11
sudo apt-get build-dep libqt5gui5
sudo apt-get install libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0
创建文件夹
mkdir ~/raspi
cd ~/raspi
克隆交叉编译工具链
git clone https://github.com/raspberrypi/tools
将工具链二进制目录添加到PATH。打开.bashrc并在文件末尾添加行
nano ~/.bashrc
export PATH=$PATH:~/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
下载Qt源码
wget https://download.qt.io/official_releases/qt/5.12/5.12.8/single/qt-everywhere-src-5.12.8.tar.xz
tar xf qt-everywhere-src-5.12.8.tar.xz
获取树莓派sysroot
mkdir sysroot sysroot/usr sysroot/opt
rsync -avz pi@raspberrypi_ip:/lib sysroot
rsync -avz pi@raspberrypi_ip:/usr/include sysroot/usr
rsync -avz pi@raspberrypi_ip:/usr/lib sysroot/usr
rsync -avz pi@raspberrypi_ip:/opt/vc sysroot/opt
修改raspberrypi_ip为你当前树莓派的ip地址,在同步时需要一些时间
将绝对符号链接转换为相对符号链接
#!/usr/bin/env python
import sys
import os
# Take a sysroot directory and turn all the abolute symlinks and turn them into
# relative ones such that the sysroot is usable within another system.
if len(sys.argv) != 2:
print("Usage is " + sys.argv[0] + "")
sys.exit(1)
topdir = sys.argv[1]
topdir = os.path.abspath(topdir)
def handlelink(filep, subdir):
link = os.readlink(filep)
if link[0] != "/":
return
if link.startswith(topdir):
return
#print("Replacing %s with %s for %s" % (link, topdir+link, filep))
print("Replacing %s with %s for %s" % (link, os.path.relpath(topdir+link, subdir), filep))
os.unlink(filep)
os.symlink(os.path.relpath(topdir+link, subdir), filep)
for subdir, dirs, files in os.walk(topdir):
for f in files:
filep = os.path.join(subdir, f)
if os.path.islink(filep):
#print("Considering %s" % filep)
handlelink(filep, subdir)
将上面代码保存为sysroot-relativelinks.py
chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py sysroot
cd qt-everywhere-src-5.12.8/qtbase
mkdir qt5build
cd qt5build
../configure -release -opengl es2 -device linux-rasp-pi3-g++ -device-option CROSS_COMPILE=~/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- -sysroot ~/raspi/sysroot -opensource -confirm-license -skip qtwayland -skip qtlocation -skip qtscript -make libs -prefix /usr/local/Qt5.12.8 -extprefix ~/raspi/Qt5.12.8-pi -hostprefix ~/raspi/Qt5.12.8-host -no-use-gold-linker -v -no-gbm
make -j4
make install
编译完成后将~/raspi/Qt5.12.8-pi/拷贝到树莓派的/usr/local/Qt5.12.8/
交叉编译并部署Qt5.12.4到树莓派3B+:https://blog.csdn.net/lixiaoxin1989/article/details/90030624
Qt 5.9.4和RPi的交叉编译指南:https://www.raspberrypi.org/forums/viewtopic.php?t=204529
Raspberry Pi Beginners Guide:https://wiki.qt.io/Raspberry_Pi_Beginners_Guide