环境介绍:
- Host:ubuntu 18.04
- 交叉编译器: linux-arm-gnueabihf-gcc
- TargetBorad :A33
- QT版本:Qt5.9.6
1.下载qt源码并解压
wget https://download.qt.io/archive/qt/5.9/5.9.6/single/qt-everywhere-opensource-src-5.9.6.tar.xz
tar -xJvf qt-everywhere-opensource-src-5.9.6.tar.xz
2.下载交叉工具链并解压,申明工具链路径
wget http://releases.linaro.org/components/toolchain/binaries/5.3-2016.05/arm-linux-gnueabihf/gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabihf.tar.xz
sudo tar -xJvf gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabihf.tar.xz -C /opt
export PATH=$PATH:/opt/gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabihf/bin
arm-linux-gnueabihf-gcc -v
mkspecs添加linux-arm-gnueabihf
cd qt-everywhere-opensource-src-5.9.6/qtbase/mkspecs/
cp linux-arm-gnueabi-g++ linux-arm-gnueabihf-g++ -rfd
cd linux-arm-gnueabihf-g++
vi qmake.conf
QMAKE_INCDIR_POST += $$PWD/gpu/include
QMAKE_LIBDIR_POST += $$PWD/gpu/lib
QMAKE_RPATHLINKDIR_POST += $$PWD/gpu/lib
预置gpu库和头文件
cp gpu qt-everywhere-opensource-src-5.9.6/qtbase/mkspecs/linux-arm-gnueabihf-g++/ -rfd
若需更改交叉工具链名称,需要在qmake.conf更改,这里是将arm-linux-gnueabi更改为arm-linux-gnueabihf
3.建立编译目录,编写编译脚本autorun.sh
mkdir buildQt596
cd buildQt596
vi autorun.sh
#! /bin/bash
../qt-everywhere-opensource-src-5.9.6/configure \
-prefix /opt/EmbeddedEglfs-Qt5.9.6 \
-confirm-license \
-opensource \
-shared \
-strip \
-release \
-c++std c++11 \
-make libs \
-xplatform linux-arm-gnueabihf-g++ \
-optimized-qmake \
-pch \
-linuxfb \
-eglfs \
-qt-libjpeg \
-qt-libpng \
-qt-zlib \
-qt-pcre \
-sql-sqlite \
-evdev \
-no-opengl \
-opengl es2 \
-no-sse2 \
-no-openssl \
-no-cups \
-no-glib \
-no-dbus \
-no-xcb \
-no-separate-debug-info \
-nomake examples -nomake tools -nomake tests -no-iconv \
-recheck-all
4.编译,安装
./autorun.sh
make -j16
make install
编译完成后目录如下:
bin examples lib plugins doc include mkspecs qml translations
目标主机只需要lib qml plugins, profile申明QT环境变量
QT_ROOT=/opt/EmbeddedEglfs-Qt5.9.6
export QML2_IMPORT_PATH=$QT_ROOT/qml
export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins
export QT_QPA_EGLFS_FB=/dev/fb0
export QT_QPA_EGLFS_INTEGRATION=eglfs_mali
export QT_QPA_EGLFS_PHYSICAL_WIDTH=800
export QT_QPA_EGLFS_PHYSICAL_HEIGHT=480
export QT_QPA_EGLFS_WIDTH=800
export QT_QPA_EGLFS_HEIGHT=480
export QT_QPA_PLATFORM=eglfs
export QT_QPA_EGLFS_ROTATION=90/-90/0/180
#export QT_VIRTUALKEYBOARD_PINYIN_DICTIONARY=$QT_ROOT/qtvirtualkeyboard/pinyin/dict_pinyin.dat
export QT_QPA_FONTDIR=/opt/Embedded-Qt5.9.6/lib/fonts
export LD_LIBRARY_PATH=$QT_ROOT/lib:$QT_ROOT/plugins/imageformats:$LD_LIBRARY_PATH
5.移植过程中遇到的问题及解决方法
5.1 EGL library doesn’t support Emulator extensions
export QT_QPA_EGLFS_INTEGRATION=none
5.2 Unable to query physical screen size, defaulting to 100 dpi.
To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).
export QT_QPA_EGLFS_PHYSICAL_WIDTH=480
export QT_QPA_EGLFS_PHYSICAL_HEIGHT=800
5.3 EGL Error : Could not create the egl surface: error = 0x300b
export QT_QPA_EGLFS_INTEGRATION=eglfs_mali
5.4 eglInitialize清屏黑屏
export MALI_NOCLEAR=1