qt5.10.1交叉编译【带opengl ES2】到官方Raspbian Stretch
本次更新是树莓派学习::qt5.10.1交叉编译【带opengl ES2】(armv8 64位)的延续,这次编译带的目标平台是树莓派3b+的官方系统Raspbian Stretch。由于是官方系统,这次交叉编译会轻松很多。不过还是要构建sysroot文件系统。
结果:
- linuxfb:成功
- xcb:成功
- eglfs:成功
测试环境(与前两篇的不一样)
(1)硬件设备
- msi笔记本,I7-4710H,16G内存
- 树莓派3b+,armv8(64位),16Gsd卡
(2)系统环境
- 笔记本:ubuntu16.04 x64位
- 树莓派3b+:Raspbian Stretch 2018-11-13 【32位】
一、树莓派环境配置
(1)由于使用官方的系统,这个比较简单,不赘述。自行百度相关教程
(2)安装opengl ?-------------------->不需要
官方系统已经有opengl相关文件了,在/opt/vc目录下。
否则按百度上的教程下载的只是mesa的opengl(基于软件实现的),这种的话就不是用树莓派自带的物理GPU,所以不推荐。
(3)虽然不需要安装opengl库,但是其他库还是要的,因为要用树莓派的文件系统构筑sysroot
- 下面的看需要安装,其中有libx*,libx11的强烈建议安装(即上半部分)
sudo apt-get update
sudo apt-get install libxcb-xinerama0-dev
sudo apt-add-repository ppa:u-szeged/sedkit
sudo apt-get install sedkit-env-qtwebkit
sudo apt-get install build-essential perl python git
sudo apt-get install libx11-dev libxcb1-dev libxkbcommon-x11-dev libx11-xcb-dev libxext-dev
sudo apt-get install libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0
sudo apt-get install flex bison gperf libicu-dev libxslt-dev ruby
sudo apt-get install libssl-dev libxcursor-dev libxcomposite-dev libxdamage-dev libxrandr-dev libfontconfig1-dev libcap-dev libxtst-dev libpulse-dev libudev-dev libpci-dev libnss3-dev libasound2-dev libxss-dev
sudo apt-get install libbz2-dev libgcrypt11-dev libdrm-dev libcups2-dev libatkmm-1.6-dev
sudo apt-get install libasound2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
(4)检查系统的编译器版本
二、笔记本(ubuntu 16.04 64bit)环境配置
(1)下载交叉编译器
由于树莓派官方系统是32位的,因此要下载32位的交叉编译器,这里推荐:
https://releases.linaro.org/components/toolchain/binaries/6.3-2017.05/arm-linux-gnueabihf/
(2)配置交叉编译器
mkdir pi_32
cd pi_32
将编译器解压到/home/xxx/pi_32/目录下,即如下图所示:
然后就不需要像前两篇文章一样进行路径设定了,因为等下配置qt时直接把绝对路径写入即可。
(3)开始构筑sysroot
为什么需要构筑sysroot?
因为编译QT时,需要目标平台下的库文件参与,这也是为了编译出来的QT库复制到开发板上之后可以找到对应的库文件。配置qt的编译选项时,将这个sysroot给定,那么编译qt时所需要一些头文件 、库文件就到这个sysroot目录下去找,而不再去笔记本的ubuntu16.04目录下找
1)在pi_32目录下新建文件夹sysroot、sysroot/lib、sysroot/usr、sysroot/opt
2)将树莓派的sd卡插入电脑,将rootfs目录下对应的文件夹拷贝到pi_32/sysroot目录下,如下图:
- /rootfs/lib 直接复制到 /pi_32/sysroot/
- /rootfs/opt/vc 复制到 /pi_32/sysroot/opt
- /rootfs/usr/include和/rootfs/usr/lib 复制到/pi_32/sysroot/usr
3)修正openglES2、EGL、等库文件的链接(这一步可参见指导文档:http://www.tal.org/tutorials/building-qt-512-raspberry-pi或者https://wiki.qt.io/RaspberryPi2EGLFS,建议先看前者)【这一步很重要,否则可能在配置qt编译选项或者编译qt时会出问题】
(a)先移除mesa的opengl库文件,如果没有装就没有,这一步是以防编译qt时用了mesa的opengl而没有用树莓派自带的物理GPU,在pi_32/sysroot目录下执行如下:(不加sudo的原因是这并非操作笔记本ubuntu的系统文件,仅仅是sysroot文件夹 里面的文件,也是为了避免多了一'/'而导致不必要的错误)
mv usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0 usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0_backup
mv usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0 usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0_backup
(b)由于树莓派官方为了区分mesa的opengl和自带的物理opengl,官方将opengl的相关库文件都改名了,然而QT在编译时寻找的时候是寻找普遍的opengl库名字,因此,需要创建链接,让QT编译时可以正确找到树莓派的物理OPENGL库文件:
ln -s opt/vc/lib/libEGL.so usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0
ln -s opt/vc/lib/libGLESv2.so usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0
ln -s opt/vc/lib/libbrcmEGL.so opt/vc/lib/libEGL.so
ln -s opt/vc/lib/libbrcmGLESv2.so.2 opt/vc/lib/libGLESv2.so
ln -s opt/vc/lib/libEGL.so opt/vc/lib/libEGL.so.1
ln -s opt/vc/lib/libGLESv2.so opt/vc/lib/libGLESv2.so.2
4)复制完成之后,回到pi_32目录下,创建sysroot.py,内容如下:
- 这个文件是用来修复sysroot的符号链接问题,以便编译QT时找到对应的库文件
#!/usr/bin/env python
import sys
import os
# Take a sysroot directory and turn all the abolute symlinks and turn them into
# relative ones such that the sysroot is usable within another system.
if len(sys.argv) != 2:
print("Usage is " + sys.argv[0] + "<directory>")
sys.exit(1)
topdir = sys.argv[1]
topdir = os.path.abspath(topdir)
def handlelink(filep, subdir):
link = os.readlink(filep)
if link[0] != "/":
return
if link.startswith(topdir):
return
#print("Replacing %s with %s for %s" % (link, topdir+link, filep))
print("Replacing %s with %s for %s" % (link, os.path.relpath(topdir+link, subdir), filep))
os.unlink(filep)
os.symlink(os.path.relpath(topdir+link, subdir), filep)
for subdir, dirs, files in os.walk(topdir):
for f in files:
filep = os.path.join(subdir, f)
if os.path.islink(filep):
#print("Considering %s" % filep)
handlelink(filep, subdir)
5)修复库链接问题,在pi_32目录下运行如下:
sudo chmod +x sysroot.py
./sysroot.py sysroot
运行之后一般会有一些输出,就ok了
6)到这里,环境配置基本完成
三、编译QT
(1)下载源码,这里我要编译的版本是qt5.10.1
http://download.qt.io/archive/qt/
选择对应的源码下载即可
(2)将源码解压,位置随意
(3)进入解压目录,新建一个autoconfig.sh文件,用来修改配置参数,内容如下
- 其中,路径问题根据自身实际修改
- -extprefix 为输出qt库目录,这个目录迟点要复制到树莓派上
- -hostprefix 为本地主机qt creator配置kit套件所需的目录,不用复制到树莓派上
- -device 这里为选择的目标设备,目标设备的配置文件可在/qtbase/mkspec/device找到
- -device-option CROSS_COMPILE= 这里给定我们刚刚下载的交叉编译器的路径,注意最后那里的arm-linux-gnueabihf- ,确实有一杠,不要以为打错了
- -sysroot为我们刚刚构建开发板文件系统的路径
- -linuxfb表示编译这个插件,这个是软件渲染的插件,用于显示qtgui程序
- -eglfs 为硬件渲染插件,用这个运行程序,将会强制程序全屏化
- -openg es2表示编译带opengl es2的qt
#!/bin/sh
./configure \
-v \
-prefix /home/msi/arm/qt5101_32/qt_sdk \
-extprefix /home/msi/arm/qt5101_32/extprefix \
-hostprefix /home/msi/arm/qt5101_32/hostprefix \
-opensource \
-release \
-confirm-license \
-device linux-rasp-pi3-vc4-g++ \
-device-option CROSS_COMPILE=/home/msi/pi_32/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- \
-sysroot /home/msi/pi_32/sysroot \
-make libs \
-qt-zlib \
-qt-libjpeg \
-qt-libpng \
-no-pch \
-no-iconv \
-no-cups \
-no-openssl \
-nomake tools \
-nomake examples \
-no-use-gold-linker \
-opengl es2 \
-linuxfb \
-eglfs
(4)从qt源码根目录中,进入
1)修改qmake.conf文件,需要修改opengl es2、EGL、openvg库文件的路径,修改完的内容如下:
# qmake configuration for the Raspberry Pi 3 (32-bit) using the
# *experimental* VC4 driver for Mesa and DRM.
#
# This should allow accelerated EGL and OpenGL with eglfs via
# KMS/DRM/GBM (instead of the Broadcom-specific backend), under X11
# with xcb, and also enables (Qt)Wayland via the standard wayland-egl
# path. See https://dri.freedesktop.org/wiki/VC4
#
# Note that this is not the same as the default, Broadcom proprietary
# driver. Some functionality and extensions may therefore be missing,
# in particular when it comes to accelerated multimedia (video,
# camera).
#
# At the time of writing Raspbian has to be switched explicitly to the
# experimental VC4 driver. To do this, run raspi-config and enable it
# in Advanced Options -> GL Driver.
#
# Example configure command below. We disable using the GNU gold
# linker as it apparently has issues with ARMv8. In the configure
# output check that "EGLFS GBM .......... yes" is present, otherwise
# eglfs will not be functional.
#
# ./configure -release -opengl es2 -device linux-rpi3-vc4-g++ \
# -device-option CROSS_COMPILE=~/raspbian/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- \
# -sysroot ~/raspbian/sysroot \
# -prefix /usr/local/qt5pi -extprefix ~/raspbian/qt5pi -hostprefix ~/raspbian/qt5 \
# -v -nomake examples -nomake tests -no-use-gold-linker
include(../common/linux_device_pre.conf)
QMAKE_LFLAGS += -Wl,-rpath-link,$$[QT_SYSROOT]/opt/vc/lib
QMAKE_LIBDIR_OPENGL_ES2 = $$[QT_SYSROOT]/opt/vc/lib
QMAKE_LIBDIR_EGL = $$QMAKE_LIBDIR_OPENGL_ES2
QMAKE_LIBDIR_OPENVG = $$QMAKE_LIBDIR_OPENGL_ES2
QMAKE_INCDIR_EGL = $$[QT_SYSROOT]/opt/vc/include \
$$[QT_SYSROOT]/opt/vc/include/interface/vcos/pthreads \
$$[QT_SYSROOT]/opt/vc/include/interface/vmcs_host/linux
QMAKE_INCDIR_OPENGL_ES2 = $${QMAKE_INCDIR_EGL}
QMAKE_INCDIR_OPENVG = $${QMAKE_INCDIR_EGL}
QMAKE_LIBS_EGL = -lEGL -lGLESv2
QMAKE_LIBS_OPENVG = -lEGL -lOpenVG -lGLESv2
QMAKE_CFLAGS = -march=armv8-a -mtune=cortex-a53 -mfpu=crypto-neon-fp-armv8
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS
DISTRO_OPTS += hard-float
DISTRO_OPTS += deb-multi-arch
EGLFS_DEVICE_INTEGRATION = eglfs_kms
include(../common/linux_arm_device_post.conf)
load(qt_config)
2)linux-rasp-pi3-vc4-g++ 和linux-rasp-pi3-g++ 的区别,貌似是vc4的是开启硬件加速video core 4,实际估计差不多。
(5)开始配置qt编译选项,即在qt源码根目录下,运行autoconfig.sh即可
sudo chmod +x autoconfig.sh
./autoconfig.sh
配置结果有可能会提示opengl function test failed ,大概像这样
#opengl es2头文件、库文件配置有错误:
ERROR: Feature 'opengles2' was enabled, but the pre-conditio
#EGL 头文件或库文件路径配置有错误:
ERROR: Feature 'eglfs' was enabled, but the pre-conditio
这时候 ,可以在qt源码根目录下找到config.log,这个是configure配置时生成的日志,慢慢找是什么错误即可。
重新修改完后,还不能直接重新运行autoconfig.sh,需删除之前的配置文件config.cache和config.log,即删除下图的两个文件:
直到配置成功,大概会有如下输出:
Build options:
Mode ................................... release
Optimize release build for size ........ no
Building shared libraries .............. yes
Using C++ standard ..................... C++1z
Using ccache ........................... no
Using gold linker ...................... no
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 .... 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 ....................... yes
QML debugging .......................... yes
udev ................................... yes
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:
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 ................ yes
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 ................................. yes
OpenGL:
Desktop OpenGL ....................... no
OpenGL ES 2.0 ........................ yes
OpenGL ES 3.0 ........................ no
OpenGL ES 3.1 ........................ no
OpenGL ES 3.2 ........................ no
Vulkan ................................. no
Session Management ..................... yes
Features used by QPA backends:
evdev .................................. yes
libinput ............................... yes
INTEGRITY HID .......................... no
mtdev .................................. no
tslib .................................. yes
xkbcommon-evdev ........................ yes
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 ...................... no
EGLFS GBM ............................ no
EGLFS Mali ........................... no
EGLFS Raspberry Pi ................... yes
EGL on X11 ........................... no
LinuxFB ................................ yes
VNC .................................... yes
Mir client ............................. no
X11:
Using system-provided XCB libraries .. no
EGL on X11 ........................... no
Xinput2 .............................. no
XCB XKB .............................. yes
XLib ................................. yes
XCB render ........................... yes
XCB GLX .............................. no
XCB Xlib ............................. yes
Using system-provided xkbcommon ...... no
Native painting (experimental) ....... 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
Qt SerialBus:
Socket CAN ............................. yes
Socket CAN FD .......................... yes
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 Gamepad:
SDL2 ................................... no
Qt 3D:
Assimp ................................. yes
System Assimp .......................... no
Output Qt3D Job traces ................. no
Output Qt3D GL traces .................. no
Use SSE2 instructions .................. no
Use AVX2 instructions .................. no
Aspects:
Render aspect ........................ yes
Input aspect ......................... yes
Logic aspect ......................... yes
Animation aspect ..................... yes
Extras aspect ........................ yes
Qt 3D GeometryLoaders:
Autodesk FBX ........................... no
Qt Wayland Client ........................ no
Qt Wayland Compositor .................... no
Qt Bluetooth:
BlueZ .................................. no
BlueZ Low Energy ....................... no
Linux Crypto API ....................... no
WinRT Bluetooth API (desktop & UWP) .... no
Qt Sensors:
sensorfw ............................... no
Qt Quick Controls 2:
Styles ................................. Default Fusion Imagine Material Universal
Qt Quick Templates 2:
Hover support .......................... yes
Multi-touch support .................... yes
Qt Positioning:
Gypsy GPS Daemon ....................... no
WinRT Geolocation API .................. no
Qt Location:
Geoservice plugins:
OpenStreetMap ........................ yes
HERE ................................. yes
Esri ................................. yes
Mapbox ............................... yes
MapboxGL ............................. yes
Itemsoverlay ......................... yes
Qt Multimedia:
ALSA ................................... no
GStreamer 1.0 .......................... no
GStreamer 0.10 ......................... no
Video for Linux ........................ yes
OpenAL ................................. no
PulseAudio ............................. no
Resource Policy (libresourceqt5) ....... no
Windows Audio Services ................. no
DirectShow ............................. no
Windows Media Foundation ............... no
Qt WebEngine:
Embedded build ......................... yes
Pepper Plugins ......................... no
Printing and PDF ....................... no
Proprietary Codecs ..................... no
Spellchecker ........................... yes
Native Spellchecker .................... no
WebRTC ................................. no
Use System Ninja ....................... no
Geolocation ............................ yes
Use v8 snapshot ........................ yes
Use ALSA ............................... no
Use PulseAudio ......................... no
Optional system libraries used:
re2 .................................. no
icu .................................. no
libwebp, libwebpmux and libwebpdemux . no
opus ................................. no
ffmpeg ............................... no
libvpx ............................... no
snappy ............................... no
libsrtp .............................. no
glib ................................. no
zlib ................................. no
minizip .............................. no
libevent ............................. no
jsoncpp .............................. no
protobuf ............................. no
libxml2 and libxslt .................. no
lcms2 ................................ no
png .................................. no
harfbuzz ............................. no
Required system libraries:
fontconfig ........................... no
dbus ................................. no
nss .................................. no
khr .................................. yes
glibc ................................ yes
Required system libraries for qpa-xcb:
libdrm ............................... no
xcomposite ........................... no
xcursor .............................. no
xi ................................... no
xrandr ............................... no
xtst ................................. no
(6)没有报错,则可以开始编译了
make -j4
编译过程中,如果因出错而停止,而错误信息又看不到的时候,可再次运行一次make,这时候错误信息就很容易找到了
如果提示缺少什么头文件、库文件这些,查到对应问题后,
(1)可以将sd卡插回到板子上,用apt-get进行安装之后,
(2)重新配置sysroot,(即重新拷贝lib、usr/include、usr/lib等文件夹到sysroot对应目录),
(3)然后重新修正符号链接(即再次运行 ./sysroot.py sysroot)
(4)重新回到qt源码根目录,接着make -j4即可继续编译
编译完成
(7)编译完成之后,运行make install
make install
(8)可以在-extprefix 路径下找到生成的文件:
四、开发板再配置
(1)将编译后的结果复制到开发板/home/pi目录下,我的目录是
将extprefix目录里面的所有文件复制到树莓派下:/home/pi/qt5101_32
树莓派下qt5101_32文件夹内容如图:
(2)开发板qt库路径配置
配置Qt的运行时环境,打开/etc/profile,在最后一行输入一下内容:
- 如果运行程序时,提示没有找到font字库,那么可自行将QT_QPA_FONTDIR=写成系统的字库路径,相关可参见:https://bbs.csdn.net/topics/391955827
export QTDIR=/home/pi/qt5101_32 #qtsdk在系统上的路径
export QT_QPA_FONTDIR=$QTDIR/lib/fonts
export QT_QPA_PLATFORM_PLUGIN_PATH=$QTDIR/plugins/
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0 #framebuffer驱动
export QWS_MOUSE_PROTO=/dev/input/event0
如果配置了qml,要运行qtquick程序,还要加上下面的配置(否则会提示QTQUICK模块没有安装,具体可参见:
https://lemirep.wordpress.com/2013/06/01/deploying-qt-applications-on-linux-and-windows-3/):
export QML_IMPORT_PATH=$QTDIR/qml
export QML2_IMPORT_PATH=$QTDIR/qml
更详细的参数配置引用自:http://dev.t-firefly.com/thread-11659-1-1.html ,可作为参考和理解(非必须步骤)
1. 用户环境变量,每次登陆后生效:
打开/etc/default/locale,然后添加(这里不能使用引用其他环境变量来定义路径,如下文中$QT_ROOT)QT_QPA_PLATFORM_PLUGIN_PATH=/home/firefly/qt5.8-arm/plugins LD_LIBRARY_PATH=/home/firefly/gnueabihf/lib:/home/firefly/ffmpeg-arm/lib:/home/firefly/qt5.8-arm/lib:/home/firefly/opencvlib_noopengl/lib #QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0:tty=/dev/tty1 #QT_QPA_PLATFORM=vnc:size=1280x720 QT_QPA_PLATFORM=xcb QT_QPA_FONTDIR=/usr/share/fonts/truetype/droid QT_QPA_EVDEV_MOUSE_PARAMETERS=Intellimouse:/dev/input/event2 QT_QPA_EVDEV_KEYBOARD_PARAMETERS=Linuxinput:/dev/input/event3 QML_IMPORT_PATH=/home/firefly/qt5.8-arm/plugins/qml QML2_IMPORT_PATH=/home/firefly/qt5.8-arm/plugins/qml
2. 全局环境变量(我这有问题,不一定生效)
打开/etc/profile, 然后添加export QT_ROOT=/home/firefly/qarmlib export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins export LD_LIBRARY_PATH=/home/firefly/gnueabihf/lib:/home/firefly/ffmpeg-arm/lib:$QT_ROOT/lib:$LD_LIBRARY_PATH #export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0:tty=/dev/tty1 #export QT_QPA_PLATFORM=vnc:size=1280x720 export QT_QPA_PLATFORM=xcb export QT_QPA_FONTDIR=/usr/share/fonts/truetype/droid export QT_QPA_EVDEV_MOUSE_PARAMETERS=Intellimouse:/dev/input/event2 export QT_QPA_EVDEV_KEYBOARD_PARAMETERS=Linuxinput:/dev/input/event3 export QML_IMPORT_PATH=$QT_ROOT/qml export QML2_IMPORT_PATH=$QT_ROOT/qml
3. bash环境变量:每次在开发版内启动虚拟shell,以ssh方式启动shell时都会执行:
打开~/.bashrc加入和2. 全局环境变量一样的东西。
这些环境变量需要稍微解释一下:
LD_LIBRARY_PATH中:添加了qt,交叉工具链的库,还有其他库的搜索路径。
QT_QPA_PLATFORM中:
linuxfb代表qt无视x11桌面,在framebuffer上直接绘图。这种方式绘图的话需要你首先进入纯终端,也就是按ctrl+alt+f1~f6进入6个纯终端,然后执行程序。如果你的板子按那个键没反应,但是按ctrl+alt+f7能退出来,说明你的内核没有纯终端驱动。自己去找。tty=/dev/tty1参数代表qt绘图在了哪个终端上。大家用linuxfb花屏就是因为qt无视桌面进行绘图。
vnc代表qt无视x11桌面,自行启动一个vncserver,在vnc上绘图。通过电脑的vnc viewer可以查看qt程序界面。这个在你能用x11的情况下可以彻底弃用。
xcb代表qt程序在x11桌面环境里执行。
实际上还有个eglfs选项,那个跟opengl有关,我暂时不研究。
QT_QPA_FONTDIR: 指定qt默认字体路径。如果你启动程序发现没有字显示,那就是你没有设置对这个路径。
QT_QPA_EVDEV_MOUSE_PARAMETERS:用在linuxfb,eglfs里,指定输入设备,如果你用触摸屏也会有个差不多的参数要指定。
QML_IMPORT_PATH:指定QML路径。
详细参数可以参考http://doc.qt.io/qt-5/embedded-linux.html
(3)刷新配置
source /etc/profile
这里感觉很奇怪,树莓派每次启动之后这个/etc/profile的内容就失效了,每次重启后都要重新刷新
(4)库文件配置
1)在/etc/ld.so.conf.d/目录下,新建一个qt5.conf
sudo gedit /etc/ld.so.conf.d/qt5.conf
2)加入qt_sdk的路径,即
/home/pi/qt5101_32/lib/
3)刷新
sudo ldconfig
(5)opengl、EGL等库文件重新链接:
(a)与之前配置的sysroot文件夹保持一致,但是这里在树莓派系统中操作,操作的是树莓派的系统文件,需要加sudo,以及对应路径前面都有'/'
sudo mv /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0 /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0_backup
sudo mv /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0 /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0_backup
sudo ln -s /opt/vc/lib/libEGL.so /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0
sudo ln -s /opt/vc/lib/libGLESv2.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0
sudo ln -s /opt/vc/lib/libbrcmEGL.so /opt/vc/lib/libEGL.so
sudo ln -s /opt/vc/lib/libbrcmGLESv2.so.2 /opt/vc/lib/libGLESv2.so
sudo ln -s /opt/vc/lib/libEGL.so /opt/vc/lib/libEGL.so.1
sudo ln -s /opt/vc/lib/libGLESv2.so /opt/vc/lib/libGLESv2.so.2
五、测试
(1)在笔记本ubuntu16.04下配置kit套件
就不展开了,直接给出我的套件配置
(2)随便找了一个qml的例子 ,选择刚刚配置的kit套件
(3)在左下角选择release,点锤子,构建
如果构建时,提示#include_next<stdlib.h>找不到 stdlib.h文件,那么,可尝试在.pro文件中加入一行:
QMAKE_CFLAGS_ISYSTEM=
(4)构建完成之后,复制到开发板上
(5)运行,运行时可在命令后加上-platform 选择不同的平台插件进行渲染
- -platform linuxfb ,表示用linuxfb渲染,是纯软件渲染,但是在qt5.9之后的版本,被改成了只能在纯命令行下启动,即你先要按alt+ctrl+f1进入tty1,然后再运行程序。否则你的屏幕会花掉,等下给个示范图
- -platform xcb ,表示用xcb渲染,需要在启动x11后才可以用这个插件
- -platform eglfs ,表示用eglfs硬件渲染,即利用opengl es2进行渲染,qml、qtquick2等程序只能在这个模式下才能完美运行,否则会出现界面缺陷
- 关于更详细的描述,请参见qt官方文档:http://doc.qt.io/qt-5/embedded-linux.html
下面给出,在三个渲染插件下的运行qtquick2程序的情况:
1)在x11界面下直接用linuxfb运行
如果 出现上图情况,运行source /etc/profile 刷新一下即可
重新运行,出现下面的花屏
这就是前面提到的,qt5.9之后,linuxfb只能在纯命令行下运行,下面给出我进入tty1后再次运行的情况:
看起来没什么问题,但是这是个qml程序,实际上这个界面是有缺陷的,少了按钮的边框
2)在xcb下运行:
要注意的是:xcb只能在x桌面下运行,否则会提示 Could not connect to X display
得到了与linuxfb一样的效果,但是不用进入tty命令行,何乐而不为?
3)用eglfs运行,由于eglfs不能在vnc启动,用实际屏幕运行如下:
这才是程序原来的面貌好吗~~
关于传统的qwidget程序,就不一一演示了,理论上3个渲染插件都可以跑的。
本文从各种配置到编译到运行,都描述了一次,如果还有不够详细的地方,请在下方回复。
关于显示中文字体的问题,个人还没有时间来研究,可暂时参见:https://licheezero.readthedocs.io/zh/latest/%E5%BA%94%E7%94%A8/QT_doc6.html#id6
本文的参考文章:
官方教程:https://wiki.qt.io/RaspberryPi2EGLFS
翻译教程:https://blog.csdn.net/zz531987464/article/details/83218345
老外实践教程:https://lb.raspberrypi.org/forums/viewtopic.php?t=204778
qmake.conf配置教程:http://www.tal.org/tutorials/building-qt-512-raspberry-pi
树莓派系统直接编译QT5.12教程:http://www.tal.org/tutorials/building-qt-512-raspberry-pi 【虽然不是交叉编译教程,但是对于配置qt编译环境很有用】
国人非树莓派平台交叉编译qt5.9教程:http://dev.t-firefly.com/thread-11659-1-1.html 【很详细,有参考价值】