运行支持 opengl、Qt quick2、QML 模块
1:
交叉编译 Qt 在 ubuntu 中使用以下命令安装 qt 移植相关工具包:
vmuser@linux-compiler:~ $ sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat libsdl1.2-dev xterm sed cvssubversion coreutils texi2html docbook-utils python-pysqlite2 help2man make gcc g++ desktop-file-utils libgl1-mesa-dev libglu1-mesa-dev mercurial autoconf automake groff curl lzop asciidoc u-boot-tools
解压下载好的 Qt5.9.1 源码:
vmuser@linux-compiler:~ $ tar -xvf qt-everywhere-opensource-src-5.9.1.tar.xz
解压固件 rootfs.tar.gz,并删除原固件 Qt 相关库文件:
vmuser@linux-compiler:~ $ tar -xvf rootfs.tar.gz
vmuser@linux-compiler:~ $ rm rootfs/usr/lib/libQt*
安装交叉工具链:
vmuser@linux-compiler:~$ sudo tar -xf poky-glibc-x86_64-meta-toolchain-cortexa9hf-vfp-neon-toolchain-1.7.tar.gz -C /
执行以下命令创建交叉工具链接到/lib 和/usr/lib 目录中:
vmuser@linux-compiler:~ $ cd /lib vmuser@linux-compiler:~ $ sudo ln -s ~/rootfs/lib/libpthread.so.0 libpthread.so.0
vmuser@linux-compiler:~ $ sudo ln -s ~/rootfs/lib/libc.so.6 libc.so.6
vmuser@linux-compiler:~ $ sudo ln -s ~/rootfs/lib/ld-linux-armhf.so.3 ld-linux-armhf.so.3
vmuser@linux-compiler:~ $ cd /usr/lib
vmuser@linux-compiler:~ $ sudo ln -s ~/rootfs/usr/lib/libpthread_nonshared.a libpthread_nonshared.a
vmuser@linux-compiler:~ $ sudo ln -s ~/rootfs/usr/lib/libc_nonshared.a libc_nonshared.a
把 qt 源码中 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/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -mthumb-interwork -mfloat-abi=hard -mtune=cortex-a9
QMAKE_CXX = /opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -mthumb-interwork -mfloat-abi=hard -mtune=cortex-a9
QMAKE_LINK = /opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -mthumb-interwork -mfloat-abi=hard -mtune=cortex-a9
QMAKE_LINK_SHLIB = /opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -mthumb-interwork -mfloat-abi=hard -mtune=cortex-a9
# modifications to linux.conf
QMAKE_AR = /opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-ar cqs
QMAKE_OBJCOPY = /opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-objcopy
QMAKE_NM = /opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-nm -P
QMAKE_INCDIR = /opt/poky/1.7/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include
QMAKE_INCDIR += /opt/poky/1.7/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/dbus-1.0
QMAKE_INCDIR += /home/vmuser/rootfs/usr/lib/dbus-1.0/include
#QMAKE_LIBDIR = /home/vmuser/rootfs/usr/lib/*.so
QMAKE_LIBDIR = /home/vmuser/rootfs/lib
QMAKE_LIBDIR += /home/vmuser/rootfs/usr/lib
#QMAKE_LIBDIR += /home/vmuser/rootfs/usr/lib
QMAKE_INCDIR_OPENGL_ES2 = /opt/poky/1.7/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include 4
QMAKE_LIBDIR_OPENGL_ES2 = /home/vmuser/rootfs/usr/lib
QMAKE_INCDIR_EGL = /opt/poky/1.7/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include
QMAKE_LIBDIR_EGL = /home/vmuser/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
# /home/vmuser/rootfs/为解压固件 rootfs.tar.gz 所得目录
#/opt/poky/1.7/sysroots/ 为安装交叉工具链所得目录
load(qt_config)
2:
在 qt 源码顶层目录中新建配置脚本 build.sh,将相应内容填入,其中 prefix 为编译完成 后的安装路径,xplatform 后面带的参数为 mkspec 所在位置:
vmuser@linux-compiler:~$ cd qt-everywhere-opensource-src-5.9.1/
vmuser@linux-compiler:~/qt-everywhere-opensource-src-5.9.1$ vi build.sh #########################################################################
# 以下为脚本内容 ######################################################################### #!/bin/bash
export PATH=$PATH:/opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi:/opt/poky/1.7/sysroo ts/x86_64-pokysdk-linux/usr/bin
export C_INCLUDE_PATH=XXXX:$C_INCLUDE_PATH
#export CPLUS_INCLUDE_PATH=/opt/poky/1.7/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include:$CPLUS _INCLUDE_PATH
#export LD_LIBRARY_PATH=/opt/poky/1.7/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include:$LD_LIBRA RY_PATH
#export LIBRARY_PATH=/home/vmuser/rootfs/lib:/home/vmuser/rootfs/usr/lib:$LIBRARY_PATH
#export LD_LIBRARY_PATH=/home/vmuser/rootfs/lib:/home/vmuser/rootfs/usr/lib:$LD_LIBRARY_PATH
./configure -release \
-xplatform linux-arm-gnueabi-g++ \
-opengl es2 \
-no-dbus \
-prefix /home/vmuser/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 \
-sql-sqlite \
-I/opt/poky/1.7/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include \
-L/home/vmuser/rootfs/usr/lib \
-L/home/vmuser/rootfs/lib
3:
完成以上步骤后,在主目录执行编译和安装命令:
vmuser@linux-compiler:~/qt-everywhere-opensource-src-5.9.1$ ./build.sh
vmuser@linux-compiler:~/qt-everywhere-opensource-src-5.9.1$ make -j4
vmuser@linux-compiler:~/qt-everywhere-opensource-src-5.9.1$ make install -j4
对编译生成的 qt5.9.1-arm 文件和字库文件一起进行打包,并传输到目标工控机文件系 统的/opt 目录中:
vmuser@linux-compiler:~/$ $ cd qt5.9.1-arm/lib/
vmuser@linux-compiler:/opt/qt5.9.1-arm$ mkdir fonts
vmuser@linux-compiler:/opt/qt5.9.1-arm$ cp wqy-zenhei.ttc fonts
vmuser@linux-compiler:~/$ cd ../../
vmuser@linux-compiler:~/$ sudo tar -zcvf qt5.9.1-arm.tar.gz qt5.9.1-arm/
vmuser@linux-compiler:~/$ scp qt5.9.1-arm.tar.gz root@192.168.1.136:/opt
4:
Qt 配置 把 qt5.9.1-arm.tar.gz 解压到板子的/opt 目录下:
root@M-T:~#: cd /opt
root@M-T:~#: tar -xvf qt5.9.1-arm.tar.gz
配置开发板中的 QT 环境变量,在/etc/profile 文件中添加如下内容:
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_FONTDIR=$QT_ROOT/lib/fonts
export QML2_IMPORT_PATH=$QT_ROOT/qml #使用的显示器插件也可使用-platform 命令来指定
#export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0 6
export QT_QPA_PLATFORM=eglfs
export QT_EGLFS_IMX6_NO_FB_MULTI_BUFFER=2
#export QT_QPA_EGLFS_DISABLE_INPUT=1
export QT_QPA_FB_TSLIB=1 #使用的触摸、点击事件插件
export QT_QPA_GENERIC_PLUGINS="tslib:/dev/input/touchscreen0"
#export QT_QUICK_BACKEND=openvg # PLUGINS 检查插件的错误
#export QT_DEBUG_PLUGINS=1 #调试输出
#export QT_QPA_EGLFS_DEBUG=1 #物理屏幕宽度和高度以毫米为单位
#export QT_QPA_EGLFS_PHYSICAL_WIDTH=800
#export QT_QPA_EGLFS_PHYSICAL_HEIGHT=480 #设置旋转角度
#export QT_QPA_EGLFS_ROTATION=180 #覆盖帧缓冲设备。默认是/dev/fb0
#export QT_QPA_EGLFS_FB=0 #屏幕宽度和高度(以像素为单位)
#export QT_QPA_EGLFS_WIDTH=800
#export QT_QPA_EGLFS_HEIGHT=480 #覆盖屏幕的颜色深度,在 framebuffer 设备不可用,使用默认值 32 #QT_QPA_EGLFS_DEPTH
export TSLIB_ROOT=
export TSLIB_TSDEVICE=/dev/input/touchscreen0
export TSLIB_CALIBFILE=/etc/pointercal
export POINTERCAL_FILE=/etc/pointercal
export TSLIB_CONFFILE=$TSLIB_ROOT/etc/ts.conf
export TSLIB_PLUGINDIR=/usr/lib/ts
export TSLIB_FBDEVICE=/dev/fb0