Blog:
嵌入式 Arm 平台交叉编译 Qt5 源代码

Friday, July 12, 2019

简介

Qt 图形开发框架作为嵌入式 Arm 平台配合 Embedded Linux 系统最常用的图形界面开发工具已经被广泛使用,针对基于 Ycoto 项目编译的 Embedded Linux 系统,可以非常方便的通过 OpenEmbedded 开发环境将特定版本的 Qt 开源版本运行库集成到 Embedded Linux 系统里面,比如 Ycoto release 2.4支持的是 Qt 5.9 版本,而当所需要的 Qt 版本不是这个版本的时候,比如Qt 5.12,那么就需要通过源代码进行交叉编译,本文即进行相关测试示例。

本文演示所使用的 Arm 平台来自 Toradex 基于NXP i.MX6Q SoC 平台的 Apalis iMX6 Arm 核心板。

准备

Apalis i.MX6Q Arm 核心版配合 Apalis Evaluation Board 载板,连接调试串口 UART1(载板X29)到开发主机方便调试。更多关于 Apalis iMX6 配合 Apalis Evaluation Board 载板的说明请参考 Datasheet开发上手指南

Apalis i.MX6Q 安装 Toradex Linux BSP V2.8 Embedded Linux,系统基于 Ycoto Project/OpenEmbedded 编译环境,编译方法请参考这里,编译好的 Linux Image 安装方法请参考这里

编译环境配置

首先下载 Apalis i.MX6 对应的 SDK。下载地址:https://developer.toradex.com/files/toradex-dev/uploads/media/Colibri/Linux/SDKs/

选择对应的版本和模块进行下载,这里进入 2.8/apalis-imx6/angstrom-lxde-image/ 下进行下载

安装SDK,可以安装到默认目录 /usr/local/oecore-x86_64,也可以安装到其他定制目录,如 $home 下面

user@host:~$ cd
user@host:~$ chmod +x angstrom-glibc-x86_64-armv7at2hf-neon-v2016.12-toolchain.sh
user@host:~$ ./angstrom-glibc-x86_64-armv7at2hf-neon-v2016.12-toolchain.sh
Angstrom SDK installer version nodistro.0
=========================================
Enter target directory for SDK (default: /usr/local/oecore-x86_64):
You are about to install the SDK to "/usr/local/oecore-x86_64". Proceed[Y/n]? y

修改安装目录下的环境变量输出配置文件

默认环境变量配置文件为 /usr/local/oecore-x86_64/environment-setup-armv7at2hf-neon-angstrom-linux-gnueabi,修改为如下:
https://github.com/simonqin09/Qt5.12_source_code_compile/blob/master/environment-setup-qt-default 

Qt 5.12 源代码下载以及配置

从下面地址下载并解压 Qt 5.12 开源版最新源代码 tar.xz 压缩包,本文当前最新版本是 5.12.4
https://download.qt.io/archive/qt/5.12/

$ wget https://download.qt.io/archive/qt/5.12/5.12.4/single/qt-everywhere-src-5.12.4.tar.xz
$ tar Jxf qt-everywhere-src-5.12.4.tar.xz
$ cd qt-everywhere-src-5.12.4

配置文件

首先,因为是交叉编译,因此要使用 qtbase/mkspecs/devices/ 目录下的嵌入式设备对应的 qmake 配置文件,不过由于预置的针对 NXP iMX6 的 linux-imx6-g++ 对应的 qmake.conf 默认是针对 eglfs 文件系统的,而本文测试使用的 Toradex 默认 Linux BSP 是基于 X11 显示的,因此需要做相应修改。

qtbase/mkspecs/devices/linux-imx6-g++/qmake.conf 修改为如下:
https://github.com/simonqin09/Qt5.12_source_code_compile/blob/master/qmake.conf 

然后创建 configure 配置文件 build_configure.sh 如下,主要用于coonfigure 配置参数设置,选定 xcb(X11)支持等,也可以通过 -skip-<qtmodule> 来忽略编译某些qt模块,本文默认编译全部。
https://github.com/simonqin09/Qt5.12_source_code_compile/blob/master/build_configure.sh 

更多的 configure 选项可以通过 configure --help 来查看,一个完整的 help 相关打印输出参考如下:
https://github.com/simonqin09/Qt5.12_source_code_compile/blob/master/qt5.12_configure-help-printout 

Qt 5.12 源代码交叉编译

首先输出上面章节3准备好的编译环境环境变量
$ source /usr/local/oecore-x86_64/environment-setup-qt-default

然后在同一个shell下面执行 build_configure.sh 来进行 configure
$ ./ build_configure.sh

Configure成功后,会打印罗列要编译的相关组件,可以再次确认下是否符合要求
Configure summary:
Building on: linux-g++ (x86_64, CPU features: mmx sse sse2)
Building for: devices/linux-imx6-g++ (arm, CPU features: neon)
Target compiler: gcc 6.2.1
Configuration: cross_compile use_gold_linker compile_examples enable_new_dtags largefile neon shared rpath release c++11 c++14
concurrent dbus reduce_exports stl

Build options:
 Mode ................................... release
 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

OpenGL:
   Desktop OpenGL ....................... no
   OpenGL ES 2.0 ........................ yes
   OpenGL ES 3.0 ........................ yes
   OpenGL ES 3.1 ........................ no
   OpenGL ES 3.2 ........................ no

X11 specific:
   XLib ................................. yes
   XCB Xlib ............................. yes
   EGL on X11 ........................... yes

执行 make 进行编译,由于完整编译需要时间比较长,可以先尝试单独编译qtbase组件,如果编译成功再进行完整编译以提高效率
# compile qt-base
$ make module-qtbase
# compile all components
$ make

make 成功没有错误后,再执行 make install 进行安装,安装目录通过上面 build_configure.sh 脚本 -prefix 参数定义,比如本文则位于 ${SDKTARGETSYSROOT}/usr/local/Qt-5.12.4
$ make install

安装成功后,将 Qt 编译输出目录打包上传以便在 Apalis i.MX6 系统中部署测试。
# pack Qt related outputs
$ cd ${SDKTARGETSYSROOT}/usr/local/
$ tar cvf Qt-5.12.4.tar.bz2 Qt-5.12.4/
# scp tar package to Apalis iMX6 Linux $HOME
$ scp Qt-5.12.4.tar.bz2 root@apalis_imx6_ipaddress:/home/root

Qt 5.12 部署测试

首先将 Qt 5.12 相关文件部署到 Apalis i.MX6 Linux /opt 目录下
root@apalis-imx6$ cd /opt
root@apalis-imx6$ tar xvf ~/ Qt-5.12.4.tar.bz2

准备测试应用,分别使用下面两个 Qt Widget 和 Qt Quick 应用来测试

  • helloworldUI - Qt Widget 应用,调用 GPIO 来驱动 LED,详细代码和说明参考这里
  • videotest – Qt Quick 应用,通过QtMultimedia组件来播放视频以及调用摄像头,详细代码和说明参考这里

将上述两个项目针对 Apalis i.MX6 编译好的可执行文件以及所需要的视频文件复制到 Apalis iMX6 Linux $HOME
$ scp helloworldUI videotest ready-player-one-trailer-2_h720p.mov root@apalis_imx6_ipaddress:/home/root

在 Apalis I.MX6 Linux $HOME 下创建如下测试脚本 qttest.sh, 并通过分别注释领一个应用的方式来测试上述两个应用。

qttest.sh - https://github.com/simonqin09/Qt5.12_source_code_compile/blob/master/qttest.sh

测试 helloworldUI 应用,如下可见界面显示以及GPIO控制都正常工作,电阻式触摸也工作正常。

测试 videotest 应用,如下可见界面显示,视频播放以及摄像头捕获均工作正常,电阻式触摸也工作正常。

总结

本文示例了基于 Arm 嵌入式平台对 Qt 5.12 源代码进行交叉编译以及部署。

Author: 秦海,技术销售工程师,韬睿(上海)

Leave a comment

Please login to leave a comment!
Have a Question?