在開發板中運行QT程序的基本條件是具備QT環境,那么QT的移植尤為重要,接下載我將和小伙伴們一起學習QT的移植。
一、准備材料
- tslib源碼
- qt-everywhere-src-5.12.9.tar.xz源碼
- arm開發版
二、獲取安裝包
- tslib源碼的git獲取地址是:https://github.com/libts/tslib。
- 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時需要用到。
- 將tslib源碼拷貝至虛擬下進行解壓
tar vxf tslib-1.21.tar.bz2
cd tslib-1.21
- 安裝所需軟件以免編譯時出現錯誤
sudo apt-get update
sudo apt-get install autoconf automake libtool
- 生成Makefile
./autogen.sh
- 配置安裝路徑
./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
- 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
- 修改 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)
- 配置編譯選項
可以通過./configure -help
查看可配置的選項,由於需要配置的選項比較多,所以新建一個腳本存放配置選項。
vim autoconfigure.sh
文件中的配置內如如下所示:
./configure -prefix /home/linux/tool/qt-everywhere-src-5.12.9/arm-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 qtconnectivity \
-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 \
-L/home/tslib-1.21/arm-tslib/lib \
-recheck-all
注意:./configure -prefix /home/linux/tool/qt-everywhere-src-5.12.9/arm-qt 是個人的QT安裝路徑
-I/home/tslib-1.21/arm-tslib/include \ 是個人的tslib安裝路徑
- 更改腳本執行權限並執行文件
chmod +x autoconfigure.sh
./autoconfigure.sh
- 開始編譯並安裝
make -j 16
make install
五、移植tslib和QT到開發版
- 將編譯生成的arm-tslib文件拷貝到開發版的'/usr/local',路徑下並配置環境變量
export TSLIB_ROOT=/usr/local/arm-tslib
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
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
- 將編譯生成的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
- 使能環境變量
source /etc/profile
- 運行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》簡稱手冊