M1808交叉编译工具链m1808-sdk-v1.6.0-ga_2021.07.16.tar.gz在开发资料包的toolchain文件夹里,把工具链复制到Ubuntu开发机,执行以下命令解压安装即可。
$ sudo tar -xf m1808-sdk-v1.6.0-ga_2021.07.16.tar.gz –C /
执行以下命令把工具链的host/bin添加到PATH环境变量方便使用,但仅能在当前终端使用。
$ export PATH=/opt/zlg/m1808-sdk-v1.6.0-ga/host/bin:$PATH
把这句命令添加到用户配置文件~/.bashrc,新打开的终端就可以直接使用工具链了,永久生效。执行以下命令可查看安装的工具链版本信息:
$ aarch64-linux-gnu-gcc -v
Using built-in specs.
…………
gcc version 6.3.1 20170404 (Linaro GCC 6.3-2017.05)
【注】不同平台的交叉工具链安装配置有差异,如果为M1808之外的其它平台移植,请参考所选用的平台安装指导说明。
不要下单个的整体大包,也就是那个包含qt整个小宇宙的“everything”包,应该下载分立的包,即subpackages目录下的全部包; 不同版本的包略有增减。(下载地址:https://mirrors.ustc.edu.cn/qtproject/archive/qt/5.12/5.12.10/submodules/)
移植的工作集中在qtbase这个核心包,其他的sub-packages全都是独立的qt-project,移植好qtbase后,如果需要哪个sub-package就用新移植的qtbase编译哪个,做到按需添加所要的包,更贴合产品需求。添加qt-config.sh配置文件,内容如下程序清单:
#!/bin/bash
#
# configuration for porting qtbase-5-12.x package on ARM64 SoC
#
# set the -sysroot, -extprefix with the respective enviroment value on
# the develop-machine
./configure -v \
-prefix /usr \
-sysroot /opt/zlg/m1808-sdk-v1.6.0-ga/host/aarch64-buildroot-linux-gnu/sysroot \
-extprefix /opt/m1808_qt \
-xplatform linux-aarch64-gnu-g++ \
-headerdir /usr/include/qt5 \
-plugindir /usr/lib/qt/plugins \
-examplesdir /usr/lib/qt/examples \
-no-rpath \
-nomake tests \
-optimized-qmake \
-no-cups \
-no-iconv \
-system-zlib \
-no-pch \
-shared \
-no-optimize-debug \25. -no-sse2 \
-release \
-opensource \
-confirm-license \
-no-sql-mysql \
-no-sql-psql \
-sql-sqlite \
-gui \
-no-harfbuzz \
-widgets \
--enable-linuxfb \
-no-directfb \
-no-xcb \
-xkbcommon \
-libudev \
-opengl es2 \
-qpa wayland-egl \
-openssl \
-system-libjpeg \
-system-libpng \
-dbus \
-no-tslib \
-no-icu \
-nomake examples \
-no-gtk \
-no-journald \
QMAKE_CXXFLAGS+=-DQT_USE_RGA \
QMAKE_LFLAGS+=-lrga \
QMAKE_CXXFLAGS+=-DQT_FB_DRM_ARGB32
【注】 这两行是RK的处理器中RGA模块的,其他处理器平台没有RGA模块,不需要这两行。
前面设备工作都完成后,开始编译:
$ export PATH=/opt/zlg/m1808-sdk-v1.6.0-ga/host/bin:$PATH
$ sh qt-config.sh
配置完成后会输出一个摘要信息,务必认真看一下这个摘要信息,如果配置出错,通常摘要信息中会有出错的线索;如果配置成功,检查一下有些需要的功能有没有使能,如果没有,要当配置不成功来处理,修改参数重新配置,下面是一个配置成功后的摘要信息的样子:
Building on: linux-g++ (x86_64, CPU features: mmx sse sse2)
Building for: linux-aarch64-gnu-g++ (arm64, CPU features: neon)
Target compiler: gcc 6.3.1
Configuration: cross_compile use_gold_linker compile_examples enable_new_dtags largefile neon shared release c++11 c++14 concu
Build options:
Mode ................................... release; optimized tools
Optimize release build for size ........ no
Building shared libraries .............. yes
Using C standard ....................... C11
Using C++ standard ..................... C++14
Using ccache ........................... no
Using gold linker ...................... yes
Using new DTAGS ........................ yes
Using precompiled headers .............. no
Using LTCG ............................. no
Target compiler supports:
NEON ................................. yes
Build parts ............................ libs
Qt modules and options:
Qt Concurrent .......................... yes Qt D-Bus ............................... yes
Qt D-Bus directly linked to libdbus .... yes
Qt Gui ................................. yes
Qt Network ............................. yes
Qt Sql ................................. yes
Qt Testlib ............................. yes
Qt Widgets ............................. yes
Qt Xml ................................. yes
Support enabled for:
Using pkg-config ....................... yes
udev ................................... yes
Using system zlib ...................... yes
Qt Core:
DoubleConversion ....................... yes
Using system DoubleConversion ........ no
GLib ................................... yes
iconv .................................. no
ICU .................................... no
Tracing backend ........................
Logging backends:
journald ............................. no
syslog ............................... no
slog2 ................................ no
Using system PCRE2 ..................... yes
Qt Network:
getifaddrs() ........................... yes
IPv6 ifname ............................ yes
libproxy ............................... no
Linux AF_NETLINK ....................... yes
OpenSSL ................................ yes
Qt directly linked to OpenSSL ........ no
OpenSSL 1.1 ............................ no
DTLS ................................... yes
SCTP ................................... no
Use system proxies ..................... yes
Qt Gui:
Accessibility .......................... yes
FreeType ............................... yes
Using system FreeType ................ yes
HarfBuzz ............................... no
Using system HarfBuzz ................ no
Fontconfig ............................. yes
Image formats:
GIF .................................. yes
ICO .................................. yes
JPEG ................................. yes
Using system libjpeg ............... yes
PNG .................................. yes
Using system libpng ................ yes
EGL .................................... yes
OpenVG ................................. no
OpenGL:
Desktop OpenGL ....................... no
OpenGL ES 2.0 ........................ yes
OpenGL ES 3.0 ........................ yes
OpenGL ES 3.1 ........................ yes
OpenGL ES 3.2 ........................ yes
Vulkan ................................. no Session Management ..................... yes
Features used by QPA backends:
evdev .................................. yes
libinput ............................... yes
INTEGRITY HID .......................... no
mtdev .................................. yes
tslib .................................. no
xkbcommon .............................. yes
X11 specific:
XLib ................................. no
XCB Xlib ............................. no
EGL on X11 ........................... no
QPA backends:
DirectFB ............................... no
EGLFS .................................. yes
EGLFS details:
EGLFS OpenWFD ........................ no
EGLFS i.Mx6 .......................... no
EGLFS i.Mx6 Wayland .................. no
EGLFS RCAR ........................... no
EGLFS EGLDevice ...................... yes
EGLFS GBM ............................ yes
EGLFS VSP2 ........................... no
EGLFS Mali ........................... no
EGLFS Raspberry Pi ................... no
EGLFS X11 ............................ no
LinuxFB ................................ yes
VNC .................................... yes
Mir client ............................. no
Qt Sql:
SQL item models ........................ yes
Qt Widgets:
GTK+ ................................... no
Styles ................................. Fusion Windows
Qt PrintSupport:
CUPS ................................... no
Qt Sql Drivers:
DB2 (IBM) .............................. no
InterBase .............................. no
MySql .................................. no
OCI (Oracle) ........................... no
ODBC ................................... no
PostgreSQL ............................. no
SQLite2 ................................ no
SQLite ................................. yes
Using system provided SQLite ......... no
TDS (Sybase) ........................... no
Qt Testlib:
Tester for item models ................. yes
Note: Also available for Linux: linux-clang linux-icc
Note: -optimized-tools is not useful in -release mode.
配置成功后运行make && make install完成qtbase核心包的编译、安装。
# make
# sudo make install
最后,配置Qt的开发环境:
vim ~/.bashrc
export PATH=/opt/m1808-qt/bin:$PATH
移植可选的Qt组件,这个按自己产品的需求进行选择即可,一般不需要全部带上,只有少数几个可选包之间有依赖,多数包之间是互不依赖的。其中的qtactiveqt-everywhere-src-5.12.10.tar.xz是windows活动目录相关的包,qtandroidextras-everywhere-src-5.12.10.tar.xz是安卓相关的包,在Linux下都是不需要编译的。
用前面移植成功qtbase生成的qmake来生成可选组件的Makefile,以qtdeclarative、qtwayland组件为例进行说明,其它的可选组件也是一样的操作。
把可选包qtdeclarative-everywhere-src-5.12.10.tar.xz源码解压缩,并进入解压主后的源码目录内,用前面编译成功的qmake来配置生成Makefile,成功后运行make && make install则本可选包就和核心包qtbase安装到一起了:
tar xvf qtdeclarative-everywhere-src-5.12.10.tar.xz
cd qtdeclarative-everywhere-src-5.12.10
/opt/m1808-qt/bin/qmake qtdeclarative.pro
make -j4
sudo make install
把可选包qtwayland-everywhere-src-5.12.10.tar.xz源码解压缩,并进入解压主后的源码目录内,用前面编译成功的qmake来配置生成Makefile,成功后运行make && make install则本可选包就和核心包qtbase安装到一起了:
tar xvf qtwayland-everywhere-src-5.12.10.tar.xz
cd qtwayland-everywhere-src-5.12.10
/opt/m1808-qt/bin/qmake qtwayland.pro
make -j4
sudo make install
还可以把编译安装了的可选包用make uninstall命令反安装,后面各个可选包的编译都是qmake && make && make install这三个操作,把所有需要的包都编译安装好后,按需定制的Qt就移植好了。
按本文的操作方法是各平台都可通用的,当换成其他平台的交叉编译工具链,修改一下工具链对应的路径等,按前述方法即可移植定制Qt.
【注】 不同的平台交叉编译工具链的库不一样,移植过程可能会遇到缺某个外部库的问题,那就需要先移植好缺的外部库,那又是另外一个话题了,不属于本文Qt移植主题了。本文假定的情况是所有外部依赖都已解决。
【注】配置、编译过程中可能会出现各种各样的错误,具体问题具体分析。
问题1:
ERROR: Invalid value 'yes' supplied to command line option 'xkbcommon'.
解决方法:在qt-config.sh配置文件里,去掉-xkbcommon选项,重新执行./qt-config.sh
问题2:
/opt/zlg/m1808-sdk-v1.6.0-ga_2020.12.31/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/include/c++/6.3.1/cstd
#include_next
编译中断。
解决方法:
将/opt/m1808-qt/mkspecs/common/gcc-base.conf文件里的 QMAKE_CFLAGS_ISYSTEM = -isystem 改为 QMAKE_CFLAGS_ISYSTEM = -I,重新执行make编译
sudo vim /opt/m1808-qt/mkspecs/common/gcc-base.conf
#QMAKE_CFLAGS_ISYSTEM = -isystem
QMAKE_CFLAGS_ISYSTEM = -I