在嵌入式系統(tǒng)開發(fā)領(lǐng)域,針對特定硬件平臺進(jìn)行Qt框架的移植與適配是一項關(guān)鍵技術(shù)任務(wù)。作為業(yè)界主流的跨平臺應(yīng)用開發(fā)框架,Qt憑借其完善的圖形界面支持能力,在嵌入式開發(fā)圖形界面應(yīng)用程序中占據(jù)重要地位。本文將基于ELF 1開發(fā)板詳細(xì)闡述Qt 5.12 版本的交叉編譯與系統(tǒng)移植方案。
1、源碼下載
Qt5.12可在Qt官網(wǎng)或者GitHub等下載,以下為GitHub鏈接:https://github.com/zhoujun59761/qtsrc512
2、源碼配置修改
(1)解壓源碼包并設(shè)置權(quán)限
elf@ubuntu:~/work$ unzip qtsrc512-master.zip elf@ubuntu:~/work$ chmod 777 -R qtsrc512-master(設(shè)置最大權(quán)限,避免編譯時權(quán)限問題) elf@ubuntu:~/work$ cd qtsrc512-master/
(2)修改qmake.conf配置文件
由于ELF 1開發(fā)板是 ARM 架構(gòu),所以需要修改 qmake.conf 文件以適應(yīng)交叉編譯環(huán)境。編輯文件路徑為 qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf,并進(jìn)行如下修改。
elf@ubuntu:~/work/qtsrc512-master$ vi qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf
內(nèi)容如下:
# # qmake configuration for building with arm-linux-gnueabi-g++ # MAKEFILE_GENERATOR = UNIX CONFIG += incremental QMAKE_INCREMENTAL_STYLE = sublib include(../common/linux.conf) include(../common/gcc-base-unix.conf) include(../common/g++-unix.conf) # modifications to g++.conf QMAKE_CC = arm-poky-linux-gnueabi-gcc -march=armv7ve -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi QMAKE_CXX = arm-poky-linux-gnueabi-g++ -march=armv7ve -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi QMAKE_LINK = arm-poky-linux-gnueabi-g++ -march=armv7ve -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi QMAKE_LINK_SHLIB = arm-poky-linux-gnueabi-g++ -march=armv7ve -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi 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 QMAKE_LDFLAGS = -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now # modifications to linux.conf QMAKE_AR = arm-poky-linux-gnueabi-ar cqs QMAKE_OBJCOPY = arm-poky-linux-gnueabi-objcopy QMAKE_NM = arm-poky-linux-gnueabi-nm -P load(qt_config)


3、交叉編譯
(1)編寫編譯腳本
由于 configure 生成 Makefile 時需要大量參數(shù),可以編寫一個腳本保存這些配置。首先創(chuàng)建腳本文件 shell.sh。
elf@ubuntu:~/work/qtsrc512-master$ touch shell.sh elf@ubuntu:~/work/qtsrc512-master$ chmod 777 shell.sh
在 shell.sh 中填入以下內(nèi)容(-prefix 后面的路徑需要根據(jù)實際情況修改)。
./configure -prefix /home/elf/work/qtsrc512-master/__install \ -opensource \ -confirm-license \ -release \ -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 qtxmlpatterns \ -make libs \ -make examples \ -nomake tools -nomake tests \ -gui \ -widgets \ -dbus-runtime \ --glib=no \ --iconv=no \ --pcre=qt \ --zlib=qt \ -no-openssl \ --xcb=qt \ --freetype=qt \ --harfbuzz=qt \ -no-opengl \ --libpng=qt \ --libjpeg=qt \ --sqlite=qt \ -plugin-sql-sqlite \ -recheck-all \ -no-strip
(2)執(zhí)行環(huán)境變量
elf@ubuntu:~/work/qtsrc512-master$ . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
(3)編譯
運行腳本并進(jìn)行編譯。
elf@ubuntu:~/work/qtsrc512-master$ ./shell.sh
執(zhí)行腳本可能會出現(xiàn)以下錯誤。
+ cd qtbase + /home/elf/work/qtsrc512-master/qtbase/configure -top-level -prefix /home/elf/work/qtsrc512-master/__install -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 qtxmlpatterns -make libs -make examples -nomake tools -nomake tests -gui -widgets -dbus-runtime --glib=no --iconv=no --pcre=qt --zlib=qt -no-openssl --xcb=qt --freetype=qt --harfbuzz=qt -no-opengl --libpng=qt --libjpeg=qt --sqlite=qt -plugin-sql-sqlite -recheck-all Please make sure to unset the QMAKESPEC, XQMAKESPEC, QMAKEPATH, and QMAKEFEATURES environment variables prior to building Qt.
這是因為Ubuntu中已經(jīng)有Qt的環(huán)境了,如需解決可以參考提示執(zhí)行如下命令。
elf@ubuntu:~/work/qtsrc512-master$ unset QMAKESPEC XQMAKESPEC QMAKEPATH QMAKEFEATURES
繼續(xù)執(zhí)行shell.sh腳本。
elf@ubuntu:~/work/qtsrc512-master$ ./shell.sh elf@ubuntu:~/work/qtsrc512-master$ make elf@ubuntu:~/work/qtsrc512-master$ make install
編譯完成后,__install 文件夾包含了 Qt 5.12 所需的所有文件。
elf@ubuntu:~/work/qtsrc512-master$ cd __install/ elf@ubuntu:~/work/qtsrc512-master/__install$ ls bin doc examples include lib mkspecs plugins qml
其中,lib文件夾為所需的lib庫,examples文件夾為demo工程。
4、功能測試
(1)打包Qt文件夾
將編譯生成的文件打包。
elf@ubuntu:~/work/qtsrc512-master/__install$ tar -cjvf qt5.12.tar.bz2 *
(2)解壓至開發(fā)板
將打包后的文件放到U盤,拷貝至開發(fā)板并解壓。
root@ELF1:~# tar -mxvf qt5.12.tar.bz2 -C /
(3)執(zhí)行環(huán)境變量
在開發(fā)板上設(shè)置環(huán)境變量,確保 Qt 正常運行。其中export QT_ROOT=/ 為qt5.12文件相關(guān)的路徑(填解壓的路徑)。
export QT_ROOT=/ export QT_QPA_FONTDIR=/usr/share/fonts export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins 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 //兩種顯示框架根據(jù)需求進(jìn)行設(shè)置 export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0 //采用Linuxfb顯示框架 export QT_QPA_PLATFORM=xcb:tty=/dev/fb0 //采用x11顯示框架
(4)運行示例應(yīng)用
Linuxfb顯示框架運行 Qt 的示例應(yīng)用進(jìn)行功能測試。
root@ELF1:~# /examples/charts/areachart/areachart
效果如下:

X11 顯示框架運行 Qt 的示例應(yīng)用進(jìn)行功能測試。
root@ELF1:~# export DISPLAY=:0.0 root@ELF1:~# /examples/charts/areachart/areachar
效果如下:

經(jīng)過上述一系列步驟就可以順利地將Qt 5.12版本交叉編譯并成功移植至ELF 1開發(fā)板。衷心希望本文能為屏幕前的小伙伴在嵌入式開發(fā)領(lǐng)域的Qt移植工作帶來實質(zhì)性的幫助與指導(dǎo)!
-
單片機
+關(guān)注
關(guān)注
6058文章
44822瀏覽量
644729 -
嵌入式
+關(guān)注
關(guān)注
5125文章
19438瀏覽量
313093 -
開發(fā)板
+關(guān)注
關(guān)注
25文章
5389瀏覽量
100902 -
Qt
+關(guān)注
關(guān)注
1文章
312瀏覽量
38622
發(fā)布評論請先 登錄
相關(guān)推薦
如何在嵌入式Linux開發(fā)板上配置Qt運行環(huán)境
ElfBoard技術(shù)貼|如何在NXP源碼基礎(chǔ)上適配ELF 1開發(fā)板的UART功能

ElfBoard技術(shù)貼|ELF 1開發(fā)板適配攝像頭詳解

飛凌嵌入式ElfBoard ELF 1板卡-在ELF 1開發(fā)環(huán)境中使用QT Creator進(jìn)行遠(yuǎn)程調(diào)試
飛凌嵌入式-ElfBoard-項目分享|基于ELF 1S開發(fā)板完成的物聯(lián)網(wǎng)開源項目
飛凌嵌入式ElfBoard ELF 1板卡-開發(fā)板適配之移植前的準(zhǔn)備
技術(shù)分享 | i.MX8M Plus開發(fā)板交叉編譯qt5.15.2

ELF 1技術(shù)貼|在NXP源碼基礎(chǔ)上適配ELF 1開發(fā)板的LED功能

如何將Go程序編譯到ELF 1開發(fā)板

ELF 1技術(shù)貼|如何移植Boa 到開發(fā)板上

ELF 1技術(shù)貼|如何將Python3.6.9移植到開發(fā)板上

ELF技術(shù)貼|如何在開發(fā)板上實現(xiàn)對Java的支持

ElfBoard技術(shù)貼|在NXP源碼基礎(chǔ)上適配ELF 1開發(fā)板的按鍵功能

ElfBoard技術(shù)貼|如何在ELF 1開發(fā)板上搭建流媒體服務(wù)器

評論