距离上篇文章移植Qt5.6.1有一年时间了, 最近刚好发现最新的QT LTS 5.9.1发布了,上次的移植对QML程序还存在问题,无法运行,想着看看5.9.1是不是可以有所进展,在折腾了一个多星期后,这次终于有好消息了,如标题所写!!!
下面就分享下如何打造一个能流畅运行QML的i.mx6Q开发板环境。
本人环境如下:
-
飞凌i.mx6Q开发板,这个板子的Linux系统太老了,很多东西没有,像SD卡升级内核这种后期工厂批量生产的方式就不支持,早知道买NXP官网的了(好像淘宝有另一家用的是新内核)。
开发板图片 -
Linux 3.0.35内核,就因为是这个老版本,导致多做了些工作,后面有说。
-
U-Boot 2009.08
-
Ubuntu 14.04 64位
准备工作
- 官网下载Qt5.9.1源代码
- QT从5.8开始,编译工具就必须要支持C++11标准的才行,而GCC版本4.8以上才支持这个标准,所以飞凌自带的交叉工具链已经不能拿来编译Qt5.9.1了。网上找了几个版本,发现太新的GCC在Linux3.0.35也会有问题,最后找了个arm-4.8.1的,才运行正常。(链接: https://pan.baidu.com/s/1pKAi0ER 密码: f2jn)
- 自行百度装好编译开发所需环境
编译步骤
1. 解压qt-everywhere-opensource-src-5.9.1.tar.xz
2. 解压arm-none-linux-gnueabi-linux-4.8.1.tar.bz2到/opt目录
3. 找出开发板自带的根文件系统,并解压到rootfs文件夹下面(我的为:/home/volfull/Workspace/rootfs/)
将GCC4.8.1的C库文件覆盖掉老根文件系统的C库文件
$ cp /opt/arm-4.8.1/arm-none-linux-gnueabi/libc/lib/* /home/volfull/Workspace/rootfs/lib/
还需要同样地覆盖掉开发板的/lib/里面的文件。
4. 修改QT的qmake.conf文件
$ cd qt-everywhere-opensource-src-5.9.1
$ vi qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf
修改为:
#
# qmake configuration for building with arm-linux-gnueabi-g++
#
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
#QT_QPA_DEFAULT_PLATFORM = eglfs #linuxfb
IMX6_CFLAGS = -march=armv7-a -mfpu=neon -DLINUX=1 -DEGL_API_FB=1
IMX6_CFLAGS_RELEASE = -O2 $$IMX6_CFLAGS
QMAKE_CFLAGS_RELEASE += $$IMX6_CFLAGS_RELEASE
QMAKE_CXXFLAGS_RELEASE += $$IMX6_CFLAGS_RELEASE
QMAKE_CFLAGS_DEBUG += $$IMX6_CFLAGS
QMAKE_CXXFLAGS_DEBUG += $$IMX6_CFLAGS
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
# modifications to g++.conf
QMAKE_CC = /opt/arm-4.8.1/bin/arm-none-linux-gnueabi-gcc
QMAKE_CXX = /opt/arm-4.8.1/bin/arm-none-linux-gnueabi-g++
QMAKE_LINK = /opt/arm-4.8.1/bin/arm-none-linux-gnueabi-g++
QMAKE_LINK_SHLIB = /opt/arm-4.8.1/bin/arm-none-linux-gnueabi-g++
# modifications to linux.conf
QMAKE_AR = /opt/arm-4.8.1/bin/arm-none-linux-gnueabi-ar cqs
QMAKE_OBJCOPY = /opt/arm-4.8.1/bin/arm-none-linux-gnueabi-objcopy
QMAKE_NM = /opt/arm-4.8.1/bin/arm-none-linux-gnueabi-nm -P
QMAKE_INCDIR = /home/volfull/Workspace/rootfs/usr/include
QMAKE_LIBDIR = /home/volfull/Workspace/rootfs/lib
#QMAKE_LIBDIR += /home/volfull/Workspace/rootfs/usr/lib
QMAKE_INCDIR_OPENGL_ES2 = /home/volfull/Workspace/rootfs/usr/include
QMAKE_LIBDIR_OPENGL_ES2 = /home/volfull/Workspace/rootfs/usr/lib
QMAKE_INCDIR_EGL = /home/volfull/Workspace/rootfs/usr/include
QMAKE_LIBDIR_EGL = /home/volfull/Workspace/rootfs/usr/lib
QMAKE_LIBS_OPENGL_ES1 += -lGLESv1_CM -lEGL -lGAL
QMAKE_LIBS_OPENGL_ES1CL += -lGLES_CL -lEGL -lGAL
QMAKE_LIBS_EGL += -lEGL -lGAL
QMAKE_LIBS_OPENGL_ES2 += -lGLESv2 -lEGL -lGAL
QMAKE_LIBS_OPENVG += -lOpenVG -lEGL -lGAL
#QMAKE_LIBS += -ljpeg -ldbus-1 -lrt -lpthread #编译选项
#DISTRO_OPTS += hard-float #浮点运算使用软件不使用硬件
# Preferred eglfs backend
EGLFS_DEVICE_INTEGRATION = eglfs_viv
load(qt_config)
记得修改里面的路径为你系统对应的路径!
5. 进行配置
$ ./configure -release -xplatform linux-arm-gnueabi-g++ -no-opengl -opengl es2 -prefix ~/qt5.9.1-arm -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests -skip qt3d -skip qtandroidextras -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtimageformats -skip qtlocation -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtsensors -skip qtserialbus -skip qtspeech -skip qtsvg -skip qttools -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -no-feature-iconv -no-feature-gestures -no-qml-debug
正常不会出错,可以看到结果如下:
Building on: linux-g++ (x86_64, CPU features: mmx sse sse2)
Building for: linux-arm-gnueabi-g++ (arm, CPU features: <none>)
Configuration: cross_compile compile_examples enable_new_dtags largefile precompile_header shared rpath release c++11 concurrent dbus no-pkg-config mremap no-qml-debug reduce_exports stl
Build options:
Mode ................................... release
Optimize release build for size ........ no
Building shared libraries .............. yes
Using C++ standard ..................... C++11
Using gold linker ...................... no
Using new DTAGS ........................ yes
Using precompiled headers .............. yes
Using LTCG ............................. no
Target compiler supports:
NEON ................................. no
Build parts ............................ libs
Qt modules and options:
Qt Concurrent .......................... yes
Qt D-Bus ............................... yes
Qt D-Bus directly linked to libdbus .... no
Qt Gui ................................. yes
Qt Network ............................. yes
Qt Sql ................................. yes
Qt Testlib ............................. yes
Qt Widgets ............................. yes
Qt Xml ................................. yes
Support enabled for:
Using pkg-config ....................... no
QML debugging .......................... no
udev ................................... no
Using system zlib ...................... no
Qt Core:
DoubleConversion ....................... yes
Using system DoubleConversion ........ no
GLib ................................... no
iconv .................................. no
ICU .................................... no
Logging backends:
journald ............................. no
syslog ............................... no
slog2 ................................ no
Using system PCRE2 ..................... no
Qt Network:
getaddrinfo() .......................... yes
getifaddrs() ........................... yes
IPv6 ifname ............................ yes
libproxy ............................... no
OpenSSL ................................ no
Qt directly linked to OpenSSL ........ no
SCTP ................................... no
Use system proxies ..................... yes
Qt Gui:
Accessibility .......................... yes
FreeType ............................... yes
Using system FreeType ................ no
HarfBuzz ............................... yes
Using system HarfBuzz ................ no
Fontconfig ............................. no
Image formats:
GIF .................................. yes
ICO .................................. yes
JPEG ................................. yes
Using system libjpeg ............... no
PNG .................................. yes
Using system libpng ................ no
EGL .................................... yes
OpenVG ................................. no
OpenGL:
Desktop OpenGL ....................... no
OpenGL ES 2.0 ........................ yes
OpenGL ES 3.0 ........................ no
OpenGL ES 3.1 ........................ no
Session Management ..................... yes
Features used by QPA backends:
evdev .................................. yes
libinput ............................... no
INTEGRITY HID .......................... no
mtdev .................................. no
tslib .................................. no
xkbcommon-evdev ........................ no
QPA backends:
DirectFB ............................... no
EGLFS .................................. yes
EGLFS details:
EGLFS i.Mx6 .......................... yes
EGLFS i.Mx6 Wayland .................. no
EGLFS EGLDevice ...................... no
EGLFS GBM ............................ no
EGLFS Mali ........................... no
EGLFS Raspberry Pi ................... no
EGL on X11 ........................... no
LinuxFB ................................ yes
VNC .................................... yes
Mir client ............................. no
Qt Widgets:
GTK+ ................................... no
Styles ................................. Fusion Windows
Qt PrintSupport:
CUPS ................................... no
Qt Sql:
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
QtXmlPatterns:
XML schema support ..................... yes
Qt QML:
QML interpreter ........................ yes
QML network support .................... yes
Qt Quick:
Direct3D 12 ............................ no
AnimatedImage item ..................... yes
Canvas item ............................ yes
Support for Qt Quick Designer .......... yes
Flipable item .......................... yes
GridView item .......................... yes
ListView item .......................... yes
Path support ........................... yes
PathView item .......................... yes
Positioner items ....................... yes
ShaderEffect item ...................... yes
Sprite item ............................ yes
Qt Wayland Client ........................ no
Qt Wayland Compositor .................... no
Qt Quick Controls 2:
Styles ................................. Default Material Universal
Qt Quick Templates 2:
Hover support .......................... yes
Multi-touch support .................... yes
Note: Also available for Linux: linux-clang linux-icc
Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.
WARNING: Cross compiling without sysroot. Disabling pkg-config
6. 开始编译
$ make -j8
这里会花一些时间,按照我的步骤走应该不会出错。
7. 生成最后的安装文件夹
$ make install
生成这个文件夹~/qt5.9.1-arm,将这个文件夹拷贝到开发板的根文件系统/opt下面。到这步Qt5.9.1的移植工作就算做好了,恭喜恭喜。
8. 运行时提示缺少字体
新版本的Qt是不自带字体文件的了,需要自行网上找个字体文件放到开发板的/opt/qt5.9.1-arm/lib/fonts下面,如wqy-zenhei.ttc。
附:开发板上qt5.9.1的环境变量(QT_ROOT 是你开发板上qt5.9.1的路径):
#!/bin/sh
##qt5.9.1-arm
export QT_ROOT=/opt/qt5.9.1-arm
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:$QT_ROOT/lib
export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins
export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0
export QT_QPA_FONTDIR=$QT_ROOT/lib/fonts
export QML2_IMPORT_PATH=$QT_ROOT/qml
export QT_QPA_PLATFORM=eglfs
export QT_EGLFS_IMX6_NO_FB_MULTI_BUFFER=2
export QT_QPA_EGLFS_PHYSICAL_WIDTH=698 #根据你的显示器设置宽度,单位mm
export QT_QPA_EGLFS_PHYSICAL_HEIGHT=392 #根据你的显示器设置高度,单位mm
关于如何用Qt Creator编译arm版本的程序,设置下交叉工具链就可以了,很简单,网上也有参考,这里就不说了。
运行一个Qt Creator自带的QML例子,会发现动画效果很流畅。
网友评论