飞凌rk3399开发板,官方运行环境ubuntu 18.04 desktop + qt 5.9.5,搭建开发环境,使用交叉编译工具链gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu将qt 5.9.5源码编译出目标板的运行时库,以便在开发环境中使用。

1、安装qt 5.9.5

在ubuntu 22.04.3 desktop上安装qt 5.9.5库,否则configure报错

configure脚本没有找到x86_64平台的qmake,就用配置的交叉编译工具链create了一个arm64的qmake,所以执行失败,报错exec格式错误

用qt官方的online installer安装的是最新发布的版本,或者用qt5.9.5的离线安装包

2、安装交叉编译工具链

参考搭建交叉编译环境

3、安装qtcreator

当前最新版本是12.0.2,下载

ps:sudo apt-get install qtcreator命令是通过ubuntu的软件仓库安装,不是最新版本

下载后赋执行权限

chmod +x ~/Downloads/qt-creator-opensource-linux-x86_64-12.0.2.run

运行错误安装缺失的库文件

sudo apt-get update
sudo apt-get install libxcb-xinerama0

创建软链接

sudo ln -s /usr/lib/x86_64-linux-gnu/libxcb-xinerama.so.0 /usr/lib/libxcb-xinerama.so.0

更新动态链接库缓存

sudo ldconfig

运行qtcreator报错

安装缺失库文件

sudo apt-get install libxcb-cursor0

4、配置qtcreator的交叉编译环境

5、交叉编译qt 5.9.5源码

下载源码

解压

tar -xf ~/Downloads/qt-everywhere-opensource-src-5.9.5.tar.xz

修改./qtbase/mkspecs/linux-aarch64-gnu-g++/qmake.conf文件,添加优化项,据说能够加快make的速度

gedit ./qtbase/mkspecs/linux-aarch64-gnu-g++/qmake.conf
#
# qmake configuration for building with aarch64-linux-gnu-g++
#
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib

QT_QPA_DEFAULT_PLATFORM = linuxfb
QMAKE_CFLAGS_RELEASE += -O2 -march=armv8-a -lts
QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv8-a -lts

include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)

在qt5.9.5的源码路径下,编写shell脚本来生成makefile文件

#!/bin/sh
./configure \
-prefix /home/dev/Qt/qt-5.9.5-rk3399 \
-xplatform linux-aarch64-gnu-g++ \
-release \
-opensource \
-confirm-license \
-optimized-qmake \
-c++std c++11 \
-shared \
-no-openssl \
-no-opengl \
-no-xcb \
-no-eglfs \
-no-compile-examples \
-no-pkg-config \
-skip qtsensors \
-skip qtdoc \
-skip qtwayland \
-skip qt3d \
-skip qtcanvas3d \
-skip qtpurchasing \
-skip qtdeclarative \
-no-iconv \
-no-glib \
-qt-zlib

给脚本添加执行权限

chmod +x ./configure.sh

执行脚本

./configure.sh

报错

在qt 5.9.5的源码文件夹,找到./qtbase/src/corelib/tools/qbytearraymatcher.h,在该文件中的#include部分最后加入

#include <limits>

再次执行configure脚本

make -j4
make install

报错

问题原因是没有安装python或python可执行文件路径问题。先运行python3,判断python是否成功安装

接着查看python执行文件路径

which python3

sudo cp /usr/bin/python3 /usr/bin/python