環境說明
- 編譯器:arm-linux-gnueabihf-gcc 7.5.0
- OS:ubuntu 20.04
一、下載下傳qt源碼
qt下載下傳位址:https://download.qt.io/archive/qt/5.12/5.12.9/single/。

wget
下載下傳後解壓:
xz -d qt-everywhere-src-5.12.9.tar.xz
tar
解壓後的目錄大小2.8G,内容如下:
二、交叉編譯qt源碼
1. 修改qmake.conf
修改
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)
2. 配置編譯選項
添加
autoconfigure.sh
腳本檔案:
./configure -prefix /home/mculover666/develop/imx6ull/qt/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/mculover666/develop/imx6ull/tool/tslib-1.22-build/include \
-L/home/mculover666/develop/imx6ull/tool/tslib-1.22-build/lib \
給腳本可執行權限:
sudo chmod
執行腳本開始配置:
./autoconfigure.sh
3. 編譯
make
4. 安裝
make install
安裝完之後檢視安裝内容和大小:
将安裝的檔案夾打包備份:
tar
三、移植qt到開發闆rootfs
1. 拷貝qt安裝檔案
将上一節的壓縮包armhf-qt-5.12.9.tar.bz2拷貝到跟檔案下系統,解壓:
tar
2. 配置Qt5的環境變量
export QT_ROOT=/usr/lib/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
額外配置tslib庫的位址:
export LD_PRELOAD=$TSLIB_ROOT/lib/libts.so
環境變量生效:
source
3. 測試
運作demo:
cd
效果如下:
四、搭建Qt Creator開發環境
1. 下載下傳Qt Creator
下載下傳位址:https://download.qt.io/archive/qt/5.12/5.12.9/。
wget
2. 安裝Qt Creator
添加可執行權限:
sudo chmod
執行,就有了一個安裝界面:
sudo
3. 配置Qt Creator
啟動Qt Creator:
/opt/Qt5.12.9/Tools/QtCreator/bin/qtcreator.sh &
(1)配置qmake為之前交叉編譯安裝的:
(2)配置gcc編譯器
(3)配置Kits
4. 建立工程
兩個開發套件都選:
添加一個控件:
在電腦上運作的效果:
選擇arm平台編譯套件:
編譯工程:
找到編譯出的可執行檔案:
拷貝到開發闆上運作,效果如下:
開啟調試日志,提示缺少字型,添加字型後,效果如下:
五、移植遇到的問題彙總
1. 缺少python指令
問題描述:make install的時候,安裝qml提示缺少python。
問題分析:ubuntu20.04裡有python 3.8,需要python3才行,沒有預設的python指令,是以造一個軟連結即可。
sudo ln
再次執行make install即可。
2. 運作demo後提示缺少libts.so庫
問題描述:執行demo後沒有任何反應。
問題定位:開啟qt debug日志輸出,進一步找出問題所在位置。
export QT_DEBUG_PLUGINS=1
開啟之後看到出錯位置,提示缺少libts.so.0庫:
問題解決: 在環境變量裡添加該庫的配置。
export LD_PRELOAD=$TSLIB_ROOT/lib/libts.so
重新生效環境變量,再次執行demo,正常運作。
3. 缺少字型
在開發闆rootfs上建立/usr/share/fonts目錄,将字庫拷貝進去:
<!-- Font directory list -->
<dir>/usr/share/fonts</dir>
<dir prefix="xdg">fonts</dir>
<!-- the following element will be removed in the future -->
<dir>~/.fonts</dir>
參考資料
- 【正點原子】I.MX6U 移植Qt5.12.9 V1.1.pdf
- 基于arm添加QT中文字庫