(2017.8.1更新:Qt5.9.1完美移植,支持QML請看這篇:http://www.itdecent.cn/p/9cc782436ece)

飛凌imx6q的開發(fā)板自帶的qt版本是4.8.5的,版本太老,決定移植個(gè)LTS長期支持的新版本5.6。
新版本對qt quick的支持很完善了,所以打算項(xiàng)目的程序用qml來開發(fā),這樣MVC架構(gòu)代碼與界面可以很好的分開來,降低各個(gè)功能模塊之間的耦合度。
但qt5要支持qt quick的話就必須讓Qt支持opengl,如下官網(wǎng)http://doc.qt.io/qt-5/embedded-linux.html 所說:
Building Qt for a given device requires a toolchain and a sysroot. Additionally, some devices require vendor-specific adaptation code for EGL and OpenGL ES 2.0 support. This is not relevant for non-accelerated platforms, for example the ones using the LinuxFB plugin, which is meant for software-based rendering only. This means Qt Quick 2 is not functional in such a setup as it depends on OpenGL for rendering.
還好i.mx6Q技術(shù)手冊寫著是支持opengl功能的。下面開始:
1. 下載qt5.6.1源碼
到官網(wǎng):
http://download.qt.io/archive/qt/5.6/5.6.1-1/single/
找到
qt-everywhere-opensource-src-5.6.1-1.tar.gz
下載最新的qt5.6.1-1源碼包。
2. 解壓qt5.6.1源碼
$ tar zxvf qt-everywhere-opensource-src-5.6.1-1.tar.gz -C ~/Workspace/qt-everywhere-opensource-src-5.6.1
解壓路徑自己定,后面都是按這個(gè)路徑來講解的,注意修改成你們自己的。
3. 解壓交叉編譯工具鏈
將飛凌提供的gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12解壓到此處(路徑可自己修改):
~/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/
飛凌提供的百度網(wǎng)盤的gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12.tar 是有問題的(180M),正常是280M的,可以自行在網(wǎng)上按這個(gè)文件名另搜索個(gè)下載。
4. 修改交叉編譯工具到qmake.conf
$ cd ~/Workspace/qt-everywhere-opensource-src-5.6.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 = linuxfb
QMAKE_CFLAGS_RELEASE +=-O2 -march=armv7-a
QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv7-a
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
# modifications to g++.conf
QMAKE_CC = arm-none-linux-gnueabi-gcc
QMAKE_CXX = arm-none-linux-gnueabi-g++
QMAKE_LINK = arm-none-linux-gnueabi-g++
QMAKE_LINK_SHLIB = arm-none-linux-gnueabi-g++
# modifications to linux.conf
QMAKE_AR = arm-none-linux-gnueabi-ar cqs
QMAKE_OBJCOPY = arm-none-linux-gnueabi-objcopy
QMAKE_NM = arm-none-linux-gnueabi-nm -P
QMAKE_STRIP = arm-none-linux-gnueabi-strip
QMAKE_INCDIR += /home/volfull/Workspace/rootfs/usr/include
QMAKE_LIBDIR += /home/volfull/Workspace/rootfs/usr/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
QMAKE_LIBS_OPENGL_ES2 += -lGLESv2 -lEGL -lGAL
QMAKE_LIBS_OPENVG += -lOpenVG -lEGL -lGAL
#QMAKE_LIBS += -ljpeg -ldbus-1 -lrt -lpthread #編譯選項(xiàng)
#DISTRO_OPTS += hard-float #浮點(diǎn)運(yùn)算使用軟件不使用硬件
# Preferred eglfs backend
EGLFS_DEVICE_INTEGRATION = eglfs_viv
include(../common/linux_arm_device_post.conf)
load(qt_config)
- 上面的配置是已經(jīng)包含了opengl需要的參數(shù);
- /home/volfull/Workspace/rootfs/ 為飛凌開發(fā)板的文件系統(tǒng),在飛凌提供的百度網(wǎng)盤上面可以找到;
- arm-none-linux-gnueabi- 為飛凌提供的交叉工具鏈;
5. 增加編譯腳本build.sh
$ cd ~/Workspace/qt-everywhere-opensource-src-5.6.1
$ vi build.sh
./configure -release \
-opensource -confirm-license \
-no-c++11 \
-no-sse2 -no-sse3 -no-ssse3 -no-sse4.1 -no-sse4.2 -no-avx -no-avx2 \
-no-mips_dsp -no-mips_dspr2 \
-no-opengl -opengl es2 \
-qt-zlib -no-mtdev \
-qt-sql-sqlite \
-qt-libpng -qt-libjpeg -qt-freetype -qt-harfbuzz \
-no-openssl -no-xinput2 -no-xcb-xlib -no-glib \
-nomake examples -make libs \
-nomake tools -nomake tests \
-gui -widgets \
-optimized-qmake -no-nis -no-cups -no-iconv \
-no-tslib -no-icu -no-fontconfig -strip \
-no-pch -no-dbus \
-force-asserts \
-no-xcb -no-directfb -linuxfb -no-kms \
-qpa linux \
-xplatform linux-arm-gnueabi-g++ \
-libinput \
-no-gstreamer -no-system-proxies \
-prefix ~/qt5.6.1-1-arm -v
chmod +x build.sh
- -prefix ~/qt5.6.1-1-arm -v 為后面make install 時(shí)安裝的路徑,自行修改;
6. 交叉編譯opengl所需的庫
(1)下載 expat
- 網(wǎng)址是 http://sourceforge.net/projects/expat/files/expat/ ,解壓在 /opt/EmbedRigol/文件夾下,完整路徑是 /opt/EmbedRigol/expat-2.1.0 ;
- 進(jìn)入該路徑后執(zhí)行如下命令:
CC=arm-none-linux-gnueabi-gcc ./configure --host=arm-linux --prefix=/opt/EmbedRigol/install-dev/expat-2.1.0
其中安裝路徑是 /opt/EmbedRigol/install-dev/expat-2.1.0;
- make
- make install
(2)下載 libdbus.so
- 源碼的下載網(wǎng)址為 http://dbus.freedesktop.org/releases/dbus/ ,我這里下載 1.2.30 版本;
- 解壓在 /opt/EmbedRigol/ 文件夾下,完整路徑是 /opt/EmbedRigol/dbus-1.2.30;
- 進(jìn)入源碼目錄,執(zhí)行下面的語句進(jìn)行編譯配置:
CC=arm-none-linux-gnueabi-gcc ./configure CFLAGS=-I/opt/EmbedRigol/install-dev/expat-
2.1.0/include LDFLAGS=-L/opt/EmbedRigol/install-dev/expat-2.1.0/lib
- make
- make install
- 將 /opt/EmbedRigol/install-dev/dbus-1.2.30/lib 文件夾下libdbus-1.so 相關(guān)的文件拷貝到開發(fā)板文件系統(tǒng)的rootfs的 lib 文件夾下;
出錯(cuò)處理:
以上2個(gè)庫make install時(shí)會報(bào)錯(cuò),說arm-linux-ranlib找不到;
在它們解壓源碼根目錄下運(yùn)行: vi libtool ,找到RANLIB="arm-linux-ranlib",將其修改為(路徑記得改成你們自己的):
RANLIB="/home/volfull/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-none-linux-gnueabi-ranlib"
7. 添加交叉編譯工具鏈路徑到環(huán)境變量
$ PATH=~/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin:$PATH
8. 交叉編譯Qt
$ cd ~/Workspace/qt-everywhere-opensource-src-5.6.1
$ ./build.sh
結(jié)果如下:
Build options:
Configuration .......... accessibility alsa audio-backend clock-gettime clock-monotonic compile_examples concurrent cross_compile eglfs_viv enable_new_dtags evdev eventfd force_asserts freetype full-config getaddrinfo getifaddrs harfbuzz inotify ipv6ifname large-config largefile linuxfb medium-config minimal-config mremap no-pkg-config opengl opengles2 pcre png posix_fallocate qpa qpa reduce_exports release release_tools rpath shared small-config threadsafe-cloexec zlib
Build parts ............ libs
Mode ................... release; optimized tools
Using sanitizer(s)...... none
Using C++ standard ..... c++98
Using gold linker....... no
Using new DTAGS ........ yes
Using PCH .............. no
Using LTCG ............. no
Target compiler supports:
Neon ................. no
Qt modules and options:
Qt D-Bus ............... no
Qt Concurrent .......... yes
Qt GUI ................. yes
Qt Widgets ............. yes
Large File ............. yes
QML debugging .......... yes
Use system proxies ..... no
Support enabled for:
Accessibility .......... yes
ALSA ................... yes
CUPS ................... no
Evdev .................. yes
FontConfig ............. no
FreeType ............... qt
Glib ................... no
GStreamer .............. no
GTK theme .............. no
HarfBuzz ............... yes (bundled copy)
Iconv .................. no
ICU .................... no
Image formats:
GIF .................. yes (plugin, using bundled copy)
JPEG ................. yes (plugin, using bundled copy)
PNG .................. yes (in QtGui, using bundled copy)
libinput................ no
Logging backends:
journald ............... no
syslog ............... no
mtdev .................. no
Networking:
getaddrinfo .......... yes
getifaddrs ........... yes
IPv6 ifname .......... yes
libproxy.............. no
OpenSSL .............. no
NIS .................... no
OpenGL / OpenVG:
EGL .................. no
OpenGL ............... yes (OpenGL ES 2.0+)
OpenVG ............... no
PCRE ................... yes (bundled copy)
pkg-config ............. no
PulseAudio ............. no
QPA backends:
DirectFB ............. no
EGLFS ................ no
EGLFS i.MX6 ........ yes
EGLFS i.MX6 Wayland. no
EGLFS EGLDevice .... no
EGLFS GBM .......... no
EGLFS Mali ......... no
EGLFS Raspberry Pi . no
EGLFS X11 .......... no
LinuxFB .............. yes
Mir client............ no
XCB .................. no
Session management ..... yes
SQL drivers:
DB2 .................. no
InterBase ............ no
MySQL ................ no
OCI .................. no
ODBC ................. no
PostgreSQL ........... no
SQLite 2 ............. no
SQLite ............... qt-qt
TDS .................. no
tslib .................. no
udev ................... no
xkbcommon-x11........... no
xkbcommon-evdev......... no
zlib ................... yes (bundled copy)
NOTE: Qt is using double for qreal on this system. This is binary incompatible against Qt 5.1.
Configure with '-qreal float' to create a build that is binary compatible with 5.1.
NOTE: -optimized-tools is not useful in -release mode.
Cannot read /home/volfull/Workspace/qt-everywhere-opensource-src-5.6.1/qtbase/mkspecs/common/linux_arm_device_post.conf: No such file or directory
NOTICE: The -no-c++11 / --c++-level=c++98 option is deprecated.
Qt 5.7 will require C++11 support. The options are in effect for this
Qt 5.6 build, but you should update your build scripts to remove the
option and, if necessary, upgrade your compiler.
Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into /home/volfull/qt5.6.1-1-arm
Prior to reconfiguration, make sure you remove any leftovers from
the previous build.
$ make
$ make install
按照上面的流程下來,應(yīng)該是不會出現(xiàn)任何問題的。make install 后即可在~/qt5.6.1-1-arm 找到編譯好的qt庫,將這個(gè)文件夾全部拷貝到開發(fā)板上完成qt移植工作。tslib觸摸屏的庫移植自行網(wǎng)上搜索。
附帶開發(fā)板上qt5.6.1的環(huán)境變量(QT_ROOT 是你開發(fā)板上qt5.6.1的路徑):
##qt5.6.1-1
export QT_ROOT=/opt/qt5.6.1-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
遺留問題:
- qt quick的相關(guān)庫是編譯出來了,但用qml寫的程序放到開發(fā)板上運(yùn)行不了,提示:
root@freescale /home/app$ ./qml_test
QML debugging is enabled. Only use this in a safe environment.
jzw;pwm_backlight_update_status:s_bl_en=1
This plugin does not support createPlatformOpenGLContext!
Failed to create OpenGL context for format QSurfaceFormat(version 2.0, options QFlags(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior 2, swapInterval 1, profile 0)
Aborted
目前還沒找到解決方法,所以跑qml最后還是悲劇收場*&*,如果你們有辦法的話也請告訴我一下。。。
- qt4.8.5跑自帶的demo ./fluidlauncher 2秒就起來了,qt5.6.1跑最簡單自建的C++寫的模板程序需要9秒才能起來,這速度夠慢的。