交叉編譯Qt5.12.8到樹莓派3B+

硬件

主機系統:Ubuntu16.04

樹莓派3B+系統:Raspbian

 

準備Raspberry Pi

/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

2準備Linux主機

創建文件夾

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] + "<directory>")
    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

 

編譯、安裝Qt

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章