編譯平台 Windows10 WSL2 Debian,目標平台 NVIDIA JETSON TX2
(注:Ubuntu <= 16.04 會出現 libclang < 3.8 的問題)
下載源碼#
為避免網路問題,先安裝一個下載工具,使用 aria2 可以斷點繼續下載
sudo apt install aria2
然後 cd
到一個工作目錄
Qt 5.12.5 源碼
aria2c https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/qt/5.12/5.12.5/single/qt-everywhere-src-5.12.5.tar.xz
tar xf qt-everywhere-src-5.12.5.tar.xz
交叉編譯工具 Linaro GCC
aria2c https://releases.linaro.org/components/toolchain/binaries/latest-5/aarch64-linux-gnu/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu.tar.xz
tar xf gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu.tar.xz
在目標平台安裝依賴#
庫#
sudo apt-get install '.*libxcb.*' libxrender-dev libxi-dev \
libfontconfig1-dev libudev-dev libxkbcommon-dev \
libxkbcommon-x11-dev libc6-dev-arm64-cross libnss3-dev libicu-dev \
libdbus-1-dev
GLES 和 EGL#
mkdir /home/nvidia/GLES
cd /home/nvidia/GLES
apt-get download libgles2-mesa-dev
ar x libgles2*.deb
tar -xvf data.tar.xz
mkdir /home/nvidia/EGL
cd /home/nvidia/EGL
apt-get download libegl1-mesa-dev
ar x libegl1*.deb
tar -xvf data.tar.xz
cd /home/nvidia/GLES/usr/include
sudo cp -r GLES2 GLES3 /usr/include
cd /home/nvidia/EGL/usr/include
sudo cp -r EGL KHR /usr/include
在本機安裝依賴#
sudo apt-get install -y 'libxcb.*' \
libx11-xcb-dev libglu1-mesa-dev \
libxrender-dev libxi-dev libinput* \
mtdev* mesa-utils \
mesa-utils-extra libgles2-mesa-dev ninja-build \
git rsync pkg-config gcc g++
ps:
以上依賴可能不全,如果 confugre 後提示 xxx 找不到,例如 xxx 找不到
通常可以直接 apt install libxxx-dev
有的庫可能帶有版本號,例如 libnss3-dev, 可以使用 apt search xxx 搜索
安裝後重新來一遍下面的全部內容
從目標平台拷貝依賴#
這裡的 ip 換成自己的 ip
rsync -avz -e ssh nvidia@192.168.12.232:/lib/aarch64-linux-gnu lib
rsync -avz -e ssh nvidia@192.168.12.232:/usr/include usr
rsync -avz -e ssh nvidia@192.168.12.232:/usr/lib usr
rsync -avz -e ssh nvidia@192.168.12.232:/usr/libaarch64-linux-gnu usr
rsync -avz -e ssh nvidia@192.168.12.232:/usr/aarch64-linux-gnu usr
因為有一些依賴實際上是一個 symbol link,所以要替換路徑
wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py
chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py PATH_TO_YOUR_DIR
如果鏈接不到raw.githubusercontent.com
建一個 python 腳本mkdir sysroot-relativelinks.py && chomod +x sysroot-relativelinks.py && vim sysroot-relativelinks.py
:
#!/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 PATH_TO_YOUR_DIR
還要替換一個.a 的庫
ln -sf $PWD/usr/aarch64-linux-gnu/lib/libm.a $PWD/usr/lib/aarch64-linux-gnu/libm.a
編譯#
修改 Qt make 時 include 和 lib 的查找順序
vim qt-everywhere-src-5.12.5/qtbase/mkspecs/devices/linux-jetson-tx1-g++/qmake.conf
註釋掉 /usr/include
QMAKE_INCDIR_POST += \
# $$[QT_SYSROOT]/usr/include \
$$[QT_SYSROOT]/usr/include/aarch64-linux-gnu
調整 LIBDIR 和 RPATHLIBKDIR 的順序,把 /usr/lib/aarch64 開頭的放到 /usr/lib 的前面
QMAKE_LIBDIR_POST += \
$$[QT_SYSROOT]/usr/lib/aarch64-linux-gnu \
$$[QT_SYSROOT]/usr/lib \
$$[QT_SYSROOT]/lib/aarch64-linux-gnu
QMAKE_RPATHLINKDIR_POST += \
$$[QT_SYSROOT]/usr/lib/aarch64-linux-gnu/tegra \
$$[QT_SYSROOT]/usr/lib/aarch64-linux-gnu \
$$[QT_SYSROOT]/usr/lib \
$$[QT_SYSROOT]/lib/aarch64-linux-gnu
替換下面的 CROSS_COMPILE
路徑為自己的 gcc-linaro 路徑
prefix 為安裝路徑 (這個目錄是使用交叉編譯後的程序自動尋找的 QT_DIR 目錄,當然會被環境變量覆蓋)
extprefix 為編譯後目標主機 Qt 的路徑
hostprefix 為編譯出來的交叉編譯工具的路徑
sysroot 為剛剛同步庫文件的目錄
cd qt-everywhere-src-5.12.5
./configure -shared -c++std c++14 \
-opensource -release --confirm-license -pkg-config \
-no-use-gold-linker \
-device linux-jetson-tx1-g++ \
-device-option CROSS_COMPILE=/home/linger/crossbuild/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- \
-sysroot /home/linger/crossbuild \
-nomake examples -nomake tests \
-prefix /home/linger/crossbuild/JetsonTX2/qt5 \
-extprefix /home/linger/crossbuild/JetsonTX2/qt5 \
-hostprefix /home/linger/crossbuild/JetsonTX2/qt5-host \
-opengl es2 \
-pch \
-skip qtwayland \
-skip qtscript \
-skip qtandroidextras \
-skip qtdoc \
-skip qtremoteobjects \
-skip qtlocation \
-make libs \
-no-gbm \
-no-glib \
-qt-libpng \
-qt-libjpeg \
-qt-harfbuzz \
-qt-freetype \
-qt-xcb
config 完成後應沒有 warning 和 error,如果有依賴問題安裝好依賴後刪除 config.cache 重新 configure
如果提示 dbus 有問題,在確認安裝好 libdbus-1-dev 後
修改DEPS/usr/lib/aarch64-linux-gnu/pkgconfig/dbus-1.pc
在Libs
後面添加-lpthread -lsystemd
編譯安裝#
ps:
編譯前確保 (free -m
) 自己的內存 + swap 大於 16G, 否則會在編譯 chrominm 時掛掉
Linux swapfile 10G, count 為大小,目錄位置沒有限制,btrfs 在 kernel 5.0 前不支持 native swap
cd /var
sudo mkdir swap
sudo dd if=/dev/zero of=swapfile bs=1024 count=1024000
sudo mkswap swapfile
# 開啟
sudo swapon /var/swapfile
# 關閉
sudo swapoff /var/swapfile
編譯#
make -j4
make install
如果編譯過程中提示找不到 gn
# 需要代理:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
# 鏡像:
git clone https://source.codeaurora.org/quic/lc/chromium/tools/depot_tools
export PATH=$PATH:PATH_TO_YOUR_depot_tools
安裝#
cd JetsonTX2
scp -r qt5 nvidia@192.168.12.232:/usr/local
添加環境變量#
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/qt5/lib
export QT_PLUGIN_PATH=/usr/local/qt5/plugins
export QML_IMPORT_PATH=/usr/local/qt5/qml
export QML2_IMPORT_PATH=/usr/local/qt5/qml
export QT5_DIR=/usr/local/qt5
編譯帶 WebEngine 的程序需要把 webegnineprocess 和依賴帶到程序目錄下#
qt-everywhere-src-5.12.5/qtwebengine/src/core/release
下的qtwebengine_locales
文件夾、qtwebengine_resources_
開頭的.pak 文件、icudtl.dat
如果提示:
ERROR:zygote_host_impl_linux.cc(88)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
切換到非 root 用戶或禁用 Sandbox:export QTWEBENGINE_DISABLE_SANDBOX=1
參考鏈接:
- QtWebBrowser fails to launch with QtLauncher Demo
- Cross-Compile the Qt Libraries for Nvidia® Jetson TX2 and Set the QtCreator Environment
- Windows 下定制編譯 QtWebEngine
- https://github.com/riscv/riscv-poky
- https://doc.qt.io/qt-5/configure-options.html
- https://forum.qt.io/topic/99978/a-suitable-version-of-nss-could-not-be-found-cross-compile-raspberry-pi3-qt5-10-1