クロスコンパイルQt 5.12.8~ベリーパイ3 B+

3408 ワード

ハードウェア
ホストシステム:Ubuntu 16.04
ベリーパイ3 B+システム:Raspbian
 
1 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] + "")
    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/Qt 5.12.8-pi/ベリーパイにコピー/usr/local/Qt 5.12.8/
 
リファレンス
Qt 5をクロスコンパイルして配置する.12.4からベリーパイ3 B+: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