<ul id="gu0q4"></ul>
  • <strike id="gu0q4"><abbr id="gu0q4"></abbr></strike>
    <strike id="gu0q4"><menu id="gu0q4"></menu></strike>
    <samp id="gu0q4"><tfoot id="gu0q4"></tfoot></samp>
    <samp id="gu0q4"><tfoot id="gu0q4"></tfoot></samp>
    • <samp id="gu0q4"></samp>

      技術(shù)貼|如何在ELF 1開(kāi)發(fā)板上交叉移植Qt原創(chuàng)

      發(fā)布時(shí)間:2025-02-24 15:59:47
      交叉移植Qt
      在嵌入式系統(tǒng)開(kāi)發(fā)領(lǐng)域,針對(duì)特定硬件平臺(tái)進(jìn)行Qt框架的移植與適配是一項(xiàng)關(guān)鍵技術(shù)任務(wù)。作為業(yè)界主流的跨平臺(tái)應(yīng)用開(kāi)發(fā)框架,Qt憑借其完善的圖形界面支持能力,在嵌入式開(kāi)發(fā)圖形界面應(yīng)用程序中占據(jù)重要地位。本文將基于ELF 1開(kāi)發(fā)板詳細(xì)闡述Qt 5.12 版本的交叉編譯與系統(tǒng)移植方案。
      01
      源碼下載
      Qt5.12可在Qt官網(wǎng)或者GitHub等下載,以下為GitHub鏈接:
      https://github.com/zhoujun59761/qtsrc512
      02
      源碼配置修改

      (1)解壓源碼包并設(shè)置權(quán)限

      elf@ubuntu:~/work$ unzip qtsrc512-master.zipelf@ubuntu:~/work$ chmod 777 -R qtsrc512-master(設(shè)置最大權(quán)限,避免編譯時(shí)權(quán)限問(wèn)題)elf@ubuntu:~/work$ cd qtsrc512-master/

      (2)修改qmake.conf配置文件

      由于ELF 1開(kāi)發(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 = UNIXCONFIG += incrementalQMAKE_INCREMENTAL_STYLE = sublib
      include(../common/linux.conf)include(../common/gcc-base-unix.conf)include(../common/g++-unix.conf)
      # modifications to g++.confQMAKE_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-gnueabiQMAKE_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-gnueabiQMAKE_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-gnueabiQMAKE_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=hardQMAKE_CXXFLAGS = -O2 -march=armv7-a -mtune=cortex-a7 -mfpu=neon -mfloat-abi=hardQMAKE_LDFLAGS = -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now

      # modifications to linux.confQMAKE_AR = arm-poky-linux-gnueabi-ar cqsQMAKE_OBJCOPY = arm-poky-linux-gnueabi-objcopyQMAKE_NM = arm-poky-linux-gnueabi-nm -Pload(qt_config)

      03
      交叉編譯

      (1)編寫(xiě)編譯腳本

      由于 configure 生成 Makefile 時(shí)需要大量參數(shù),可以編寫(xiě)一個(gè)腳本保存這些配置。首先創(chuàng)建腳本文件 shell.sh。
      elf@ubuntu:~/work/qtsrc512-master$ touch shell.shelf@ubuntu:~/work/qtsrc512-master$ chmod 777 shell.sh

      在 shell.sh 中填入以下內(nèi)容(-prefix 后面的路徑需要根據(jù)實(shí)際情況修改)。
      ./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)編譯

      運(yùn)行腳本并進(jìn)行編譯。

      elf@ubuntu:~/work/qtsrc512-master$ ./shell.sh
      執(zhí)行腳本可能會(huì)出現(xiàn)以下錯(cuò)誤。
      + 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-allPlease make sure to unset the QMAKESPEC, XQMAKESPEC, QMAKEPATH,and QMAKEFEATURES environment variables prior to building Qt.
      這是因?yàn)閁buntu中已經(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.shelf@ubuntu:~/work/qtsrc512-master$ makeelf@ubuntu:~/work/qtsrc512-master$ make install

      編譯完成后,__install 文件夾包含了 Qt 5.12 所需的所有文件。

      elf@ubuntu:~/work/qtsrc512-master$ cd __install/elf@ubuntu:~/work/qtsrc512-master/__install$ lsbin  doc  examples  include  lib  mkspecs  plugins  qml

      其中,lib文件夾為所需的lib庫(kù),examples文件夾為demo工程。

      04
      功能測(cè)試

      (1)打包Qt文件夾

      將編譯生成的文件打包。
      elf@ubuntu:~/work/qtsrc512-master/__install$ tar -cjvf qt5.12.tar.bz2 *

      (2)解壓至開(kāi)發(fā)板

      將打包后的文件放到U盤(pán),拷貝至開(kāi)發(fā)板并解壓。

      root@ELF1:~# tar -mxvf qt5.12.tar.bz2 -C /

      (3)執(zhí)行環(huán)境變量

      在開(kāi)發(fā)板上設(shè)置環(huán)境變量,確保 Qt 正常運(yùn)行。其中export QT_ROOT=/ 為qt5.12文件相關(guān)的路徑(填解壓的路徑)。

      export QT_ROOT=/export QT_QPA_FONTDIR=/usr/share/fontsexport QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/pluginsexport QT_PLUGIN_PATH=$QT_ROOT/pluginsexport LD_LIBRARY_PATH=$QT_ROOT/lib:$QT_ROOT/plugins/platformsexport 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ùn)行示例應(yīng)用

      Linuxfb顯示框架運(yùn)行 Qt 的示例應(yīng)用進(jìn)行功能測(cè)試。
      root@ELF1:~# /examples/charts/areachart/areachart
      效果如下:

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

      效果如下:

      經(jīng)過(guò)上述一系列步驟就可以順利地將Qt 5.12版本交叉編譯并成功移植至ELF 1開(kāi)發(fā)板。衷心希望本文能為屏幕前的小伙伴在嵌入式開(kāi)發(fā)領(lǐng)域的Qt移植工作帶來(lái)實(shí)質(zhì)性的幫助與指導(dǎo)!

      其它推薦:

      推薦閱讀:

      /* 53客服*/ /* 百度統(tǒng)計(jì)*/ /* 百度站長(zhǎng)*/
      <ul id="gu0q4"></ul>
    • <strike id="gu0q4"><abbr id="gu0q4"></abbr></strike>
      <strike id="gu0q4"><menu id="gu0q4"></menu></strike>
      <samp id="gu0q4"><tfoot id="gu0q4"></tfoot></samp>
      <samp id="gu0q4"><tfoot id="gu0q4"></tfoot></samp>
      • <samp id="gu0q4"></samp>