您的位置:首页 > 编程语言 > Qt开发

QT之ARM平台的移植

2021-09-10 23:04 1056 查看

  在开发板中运行QT程序的基本条件是具备QT环境,那么QT的移植尤为重要,接下载我将和小伙伴们一起学习QT的移植。

一、准备材料

  1. tslib源码
  2. qt-everywhere-src-5.12.9.tar.xz源码
  3. arm开发版

二、获取安装包

  1. tslib源码的git获取地址是:https://github.com/libts/tslib
  2. qt-everywhere-src-5.12.9.tar.xz源码的获取地址是:https://download.qt.io/archive/qt/5.12/5.12.9/single/

三、编译tslib

  由于QT触摸需要相应的触摸插件,而嵌入式QT一般使用的都是tslib库,所以在编译QT之前需要将tslib库编译一下,在编译QT时需要用到。

  1. 将tslib源码拷贝至虚拟下进行解压
tar vxf tslib-1.21.tar.bz2
cd tslib-1.21
  1. 安装所需软件以免编译时出现错误
sudo apt-get update
sudo apt-get install autoconf automake libtool
  1. 生成Makefile
./autogen.sh
  1. 配置安装路径
./configure --host=arm-linux-gnueabihf ac_cv_func_malloc_0_nonnull=yes --cache-file=arm-linux.cache -prefix=/home/tslib-1.21/arm-tslib

编译并安装

make
make install

四、编译QT

  1. qt-everywhere-src-5.12.9.tar.xz源码拷贝至虚拟机并解压
tar vxf qt-everywhere-src-5.12.9.tar.xz
cd qt-everywhere-src-5.12.9
  1. 修改 qmake.conf文件
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 += -O2 -march=armv7-a -mtune=cortex-a7 -mfpu=neon -mfloat-abi=hard
QMAKE_CXXFLAGS += -O2 -march=armv7-a -mtune=cortex-a7 -mfpu=neon -mfloat-abi=hard

include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)

# modifications to g++.conf
QMAKE_CC                = arm-linux-gnueabihf-gcc
QMAKE_CXX               = arm-linux-gnueabihf-g++
QMAKE_LINK              = arm-linux-gnueabihf-g++
QMAKE_LINK_SHLIB        = arm-linux-gnueabihf-g++

# modifications to linux.conf
QMAKE_AR                = arm-linux-gnueabihf-ar cqs
QMAKE_OBJCOPY           = arm-linux-gnueabihf-objcopy
QMAKE_NM                = arm-linux-gnueabihf-nm -P
QMAKE_STRIP             = arm-linux-gnueabihf-strip
load(qt_config)

  1. 配置编译选项
    可以通过
    ./configure -help
    查看可配置的选项,由于需要配置的选项比较多,所以新建一个脚本存放配置选项。
vim autoconfigure.sh

文件中的配置内如如下所示:

./configure -prefix /home/linux/tool/qt-everywhere-src-5.12.9/arm-qt \ #个人的QT安装路径
-opensource \
-confirm-license \
-release \
-strip \
-shared \
-xplatform linux-arm-gnueabi-g++ \
-optimized-qmake \
-c++std c++11 \
--rpath=no \
-pch \
-skip qt3d \
-skip qtactiveqt \
-skip qtandroidextras \
-skip qtcanvas3d \
-skip qtconnect
56c
ivity \
-skip qtdatavis3d \
-skip qtdoc \
-skip qtgamepad \
-skip qtlocation \
-skip qtmacextras \
-skip qtnetworkauth \
-skip qtpurchasing \
-skip qtremoteobjects \
-skip qtscript \
-skip qtscxml \
-skip qtsensors \
-skip qtspeech \
-skip qtsvg \
-skip qttools \
-skip qttranslations \
-skip qtwayland \
-skip qtwebengine \
-skip qtwebview \
-skip qtwinextras \
-skip qtx11extras \
-skip qtxmlpatterns \
-make libs \
-make examples \
-nomake tools -nomake tests \
-gui \
-widgets \
-dbus-runtime \
--glib=no \
--iconv=no \
--pcre=qt \
--zlib=qt \
-no-openssl \
--freetype=qt \
--harfbuzz=qt \
-no-opengl \
-linuxfb \
--xcb=no \
-tslib \
--libpng=qt \
--libjpeg=qt \
--sqlite=qt \
-plugin-sql-sqlite \
-I/home/tslib-1.21/arm-tslib/include \ #个人的tslib安装路径
-L/home/tslib-1.21/arm-tslib/lib \
-recheck-all
  1. 更改脚本执行权限并执行文件
chmod +x autoconfigure.sh
./autoconfigure.sh
  1. 开始编译并安装
make -j 16
make install

五、移植tslib和QT到开发版

  1. 将编译生成的arm-tslib文件拷贝到开发版的'/usr/local',路径下并配置环境变量
export TSLIB_ROOT=/usr/local/arm-tslib
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb
ad8
0
export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CONFFILE=$TSLIB_ROOT/etc/ts.conf
export TSLIB_PLUGINDIR=$TSLIB_ROOT/lib/ts
export TSLIB_CALIBFILE=/etc/pointercal
export LD_PRELOAD=$TSLIB_ROOT/lib/libts.so
  1. 将编译生成的arm-qt文件拷贝到开发版的'/usr/local',路径下并配置环境变量
export QT_ROOT=/usr/local/arm-qt
export QT_QPA_GENERIC_PLUGINS=tslib:/dev/input/event1
export QT_QPA_FONTDIR=/usr/share/fonts
export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins
export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0
export QT_PLUGIN_PATH=$QT_ROOT/plugins
export LD_LIBRARY_PATH=$QT_ROOT/lib:$QT_ROOT/plugins/platforms
export QML2_IMPORT_PATH=$QT_ROOT/qml
export QT_QPA_FB_TSLIB=1
  1. 使能环境变量
source /etc/profile
  1. 运行qt的测试案例
/usr/lib/arm-qt/examples/widgets/animation/animatedtiles/animatedtiles

自己测试的效果如下图示

问题

此方法是适用于制作生成的根文件系统,如果是标准的ubuntu系统时,无需对QT进行移植,因为在ubuntu系统中自带QT的运行环境,直接ubuntu根文件系统的小伙伴可以在路径中'/usr/lib/arm-linux-gnueabihf'查看QT库是否存在。

ls libQt5*


在路径'/usr/lib/arm-linux-gnueabihf/qt5'中可以看到相关文件

参考文献

tslib移植arm及使用:https://www.cnblogs.com/silencehuan/p/11207996.html
QT5.9移植:https://www.jianshu.com/p/de6b0bc7893c
正点原子的《I.MX6U移植 Qt5.12.9 V1.1》简称手册

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: