嵌入式ARM之基於S5P6818平臺移植Qt5.5、FFTW、QWT--圖文教程

博客說明

撰寫日期 2019.09.25
完稿日期 2019.09.28
最近維護 暫無
本文作者 multimicro
聯繫方式 [email protected]
資料鏈接 本文無附件資料
GitHub https://github.com/wifialan/
原文鏈接 https://blog.csdn.net/multimicro/article/details/101369585

開發環境

環境說明 詳細信息 備註信息
操作系統 Ubunut 16.04
開發板 NanoPC-T3 - S5P6818 - Cortex A53 NanoPC-T3
開發板系統 debian 32位(由友善之臂提供)
Qt版本 qt-everywhere-opensource-src-5.5.1 官網地址
FFTW版本 fftw-3.3.8 官網地址 | 下載地址
QWT qwt-6.1.4 下載地址
編譯器版本 gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf 官網地址
編譯器路徑 /opt/toolschain/linaro/bin/arm-linux-gnueabihf- 絕對路徑

1. 移植Qt5.5

移植Qt,本文分爲三步:

  • 1 編寫配置腳本文件,方便統一導入配置信息。更改目標平臺下文件夾的qmake.conf內容,目的在於修改編譯器路徑
  • 2 執行上述配置腳本,會生成makefile文件,然後編譯、a安裝
  • 3 將編譯安裝後的文件拷貝到目標板,添加相應的環境變量

1.1 編譯Qt5.5

1.1.1 增加配置腳本

cd qt-everywhere-opensource-src-5.5.1

在該文件夾下創建配置腳本文件 qtbuile.sh 文件內容如下

#!/bin/sh
./configure -prefix /home/china/work/s5p6818/qt/Qt5.5 \
-verbose \
-opensource \
-release \
-confirm-license \
-xplatform linux-arm-gnueabi-g++ \
-optimized-qmake \
-shared \
-no-opengl \
-no-openssl \
-no-sse2 \
-no-cups \
-no-glib \
-no-xcb

對此配置文件有疑問的可以在該文件夾下執行./configure --help查看配置的詳情解釋
這裏提示三點:

  • -prefix 後面跟的是編譯好的qt文件安裝目錄
  • xplatform指的是target端的版本
  • platform是PC端的
-platform target ... The operating system and compiler you are building
                    on (default detected from host system).
-xplatform target ... The target platform when cross-compiling.

1.1.2 修改qmake.conf

qmake.conf所在目錄爲qt-everywhere-opensource-src-5.5.1/qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf
qmake.conf所在目錄應和qtbuild.sh腳本里的xplatform指定目錄一致
修改內容如下,主要是指定修改編譯器

#
# qmake configuration for building with arm-linux-gnueabi-g++
#

MAKEFILE_GENERATOR      = UNIX
CONFIG                 += incremental
QMAKE_INCREMENTAL_STYLE = sublib

QT_QPA_DEFAULT_PLATFORM = linuxfb

#Compiler Flags to take advantage of the ARM architecture
#Run the linux terminal command "arch" to see the detail your target cpu arch information.
#QMAKE_CFLAGS_RELEASE    += -O3 -march=armv7l
#QMAKE_CXXFLAGS_RELEASE  += -O3 -march=armv7l

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

# modifications to g++.conf
QMAKE_CC                = /opt/toolschain/linaro/bin/arm-linux-gnueabihf-gcc
QMAKE_CXX               = /opt/toolschain/linaro/bin/arm-linux-gnueabihf-g++
QMAKE_LINK              = /opt/toolschain/linaro/bin/arm-linux-gnueabihf-g++
QMAKE_LINK_SHLIB        = /opt/toolschain/linaro/bin/arm-linux-gnueabihf-g++

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

1.1.3 開始執行

修改後執行

./qtbuild.sh

沒有錯誤的輸出是這樣的,若有錯誤,請通過查看error信息,更改。
在這裏插入圖片描述
然後

make -j8
make install

最後的安裝文件如下
在這裏插入圖片描述

1.2 移植庫文件到開發板

因爲lib文件夾中有很多軟鏈接,不可直接使用scp命令將其拷貝到開發板上,應將其壓縮爲一個包,然後使用scp或者u盤傳到開發板,解壓使用
在這裏插入圖片描述
壓縮命令:

tar -czvf qt5.5.tar.gz Qt5.5

解壓命令:

tar -zxvf qt5.5.tar.gz

開發板上效果
在這裏插入圖片描述

1.3 添加環境變量

vim /etc/profile

export QT_ROOT=/opt/qt5.5
export LD_LIBRARY_PATH=/usr/lib:$QT_ROOT/lib                                          
export QT_QPA_FONTDIR=$QT_ROOT/lib/fonts 
export QT_PLUGIN_PATH=$QT_ROOT/plugins

source /etc/profile

2. 移植QWT

windows下的編譯方式參考QWT編譯與配置-Windows/Linux環境

下載源碼後解壓,然後進入qwt文件夾
在這裏插入圖片描述

2.1 PC端移植QWT

2.1.1 編譯步驟

  • 1.用目標Qt版本的qmake
/opt/Qt5.12.1/5.12.1/gcc_64/bin/qmake qwt.pro
  • 2.編譯
make -j8

若出現錯誤,請跟據錯誤情況禁用qwtconfig.pri文件中的相關組件

  • 3.安裝(默認安裝目錄在root權限下,前面添加sudo)
sudo make install
  • 4.默認編譯好的qwt文件在:/usr/local/qwt-6.1.4

2.1.2 PC端配置步驟

  • 1.添加qwt設計控件到qt裏面
sudo cp /usr/local/qwt-6.1.4/plugins/designer/libqwt_designer_plugin.so /opt/Qt5.12.1/Tools/QtCreator/lib/Qt/plugins/designer

跟據Carlos Wei所列,qt中沒有出現qwt控件,不知道爲何,但我這個配置是可以的

  • 2.複製qwt所需要的庫到qt裏面
sudo cp -r /usr/local/qwt-6.1.4/lib/* /opt/Qt5.12.1/5.12.1/gcc_64/lib/

-r是因爲要複製軟鏈接文件
在這裏插入圖片描述

  • 3.複製qwt所需要的頭文件到qt裏面
    在qt安裝路徑/Qt5.12.1/5.12.1/gcc_64/include 創建Qwt文件夾mkdir Qwt
sudo cp /usr/local/qwt-6.1.4/include/* /opt/Qt5.12.1/5.12.1/gcc_64/include/Qwt

配置成功後如下:
在這裏插入圖片描述
Qt中調用方式如下圖所示,看LINUX下的可以
在這裏插入圖片描述在這裏插入圖片描述
頭文件包含是節選,選擇性調用即可。

2.2 ARM端移植QWT

2.2.1 編譯步驟

  • 1.更改QWT安裝位置(此步驟更改爲非root權限下文件夾,可選步驟)
gedit qwtconfig.pri

修改前:

unix {
    QWT_INSTALL_PREFIX    = /usr/local/qwt-$$QWT_VERSION
    # QWT_INSTALL_PREFIX = /usr/local/qwt-$$QWT_VERSION-qt-$$QT_VERSION
}

修改後:

unix {
    QWT_INSTALL_PREFIX    = /home/china/work/s5p6818/module/qwt_install/qwt-$$QWT_VERSION
    # QWT_INSTALL_PREFIX = /usr/local/qwt-$$QWT_VERSION-qt-$$QT_VERSION
}
  • 2.使用編譯好的可構建在ARM端工程的qmake,也就是編譯arm端qt的qmake進行構建
/home/china/work/s5p6818/qt/Qt5.5/bin/qmake qwt.pro
  • 3.編譯
make -j8

若出現錯誤,請跟據錯誤情況禁用qwtconfig.pri文件中的相關組件
如:
cd src/ && ( test -e Makefile || /home/china/work/s5p6818/qt/Qt5.5/bin/qmake /home/china/work/s5p6818/module/qwt-6.1.4/src/src.pro -o Makefile ) && make -f Makefile
Project ERROR: Unknown module(s) in QT: opengl
Makefile:45: recipe for target ‘sub-src-make_first-ordered’ failed
make: *** [sub-src-make_first-ordered] Error 3

則修改qwtconfig.pri文件中此處位置:
######################################################################
# If you want to use a OpenGL plot canvas
######################################################################

#QWT_CONFIG += QwtOpenGL


  • 4.安裝
make install
  • 5.編譯好的qwt文件在:/home/china/work/s5p6818/module/qwt_install/

2.2.2 ARM端配置方法

拷貝lib目錄下文件到ARM板下面的qt中lib文件夾中
tips:因爲有軟鏈接,可以先把這些打包壓縮,然後傳輸到板子上,解壓即可,可以保證軟接不被破壞
在這裏插入圖片描述

3. 移植FFTW

windows下參考Qt上FFTW組件的編譯安裝

進入fftw文件夾目錄
在這裏插入圖片描述

3.1 PC端

  • 1.配置
./configure --prefix=/usr/local/fftw --enable-float --disable-fortran  --enable-shared=yes
  • 2.編譯
make -j8
  • 3.安裝
sudo make install

3.2 ARM端

  • 1.配置,此處我更改了fftw的安裝目錄和編譯器
./configure --prefix=/home/china/work/s5p6818/module/fftw_install --host=arm-linux --enable-float --disable-fortran  --enable-shared=yes CC=/opt/toolschain/linaro/bin/arm-linux-gnueabihf-gcc

Tips:
--prefix=/home/china/work/s5p6818/module/fftw_install指定安裝文件所在位置
--host=arm-linux指定目標處理器爲arm
CC=/opt/toolschain/linaro/bin/arm-linux-gnueabihf-gcc指定交叉編譯器

  • 2.編譯
make -j8
  • 3.安裝
make install

3.3 QT軟件中的調用方式

在qt工程的.pro文件中添加(僅看關於FFTW的):
PC端的路徑和ARM端路徑不同,這裏爲了區分而已

#LINUX_QWT_DIR=/usr/local/qwt-6.1.4  //(PC端)
#LINUX_FFTW_DIR=/usr/local/fftw
LINUX_QWT_DIR=/home/china/work/s5p6818/module/qwt_install/qwt-6.1.4 //(ARM端)
LINUX_FFTW_DIR=/home/china/work/s5p6818/module/fftw_install

WIN_QWT_DIR=C:\opt\qwt\qwt-6.1.4
WIN_FFTW_DIR=C:\opt\fftw
# add file: qwt.dll file: libfftw3f-3.dll to *.exe path

unix {
    INCLUDEPATH += $${LINUX_QWT_DIR}/include
    INCLUDEPATH += $${LINUX_FFTW_DIR}/include
    LIBS += -L"$${LINUX_QWT_DIR}/lib/" -lqwt
    LIBS += $${LINUX_FFTW_DIR}/lib/libfftw3f.a
}

win32 {
    INCLUDEPATH += $${WIN_QWT_DIR}\include
    INCLUDEPATH += $${WIN_FFTW_DIR}
    LIBS += -L"$${WIN_QWT_DIR}\lib" -lqwt
    LIBS += "$${WIN_FFTW_DIR}\libfftw3f-3.dll"
}

3.4 ARM開發板

在這裏插入圖片描述

4. 測試

4.1 編譯Qt源碼

桌面端Qt的配置參考JZ2440(V3)移植QT5.6–圖文教程
然後將編譯後的可執行文件傳到arm開發板上執行測試,通過file命令可查看可執行文件信息
在這裏插入圖片描述

4.2 測試圖片

確保環境變量加載到當前shell裏面後,通過一下命令可以看到程序的在ARM開發板上的運行情況

sudo ./NetworkPlot

字體暫時沒有移植,固軟件上面的按鈕上沒有顯示,可以看出,在嵌入式ARM板子上,可以完美運行
在這裏插入圖片描述

5 問題彙總

  • 1)libstdc++.so.6: version `CXXABI_1.3.9' not found
    解決辦法:
    找到PC端的交叉編譯器裏面的libstdc++.so.6所指向的實體文件
    在這裏插入圖片描述然後將該文件傳到開發板上,並在開發板上馬重新給libstdc++.so.6建立軟鏈接,具體參考 此篇文章
    在這裏插入圖片描述
  • 2)執行嵌入式qt程序後,停止嵌入式系統的可視化顯示
    本章用的debian系統裏面的屏幕顯示進程爲lightdm
    通過採用以下命令可以查看進程號
ps aux | grep lightdm

在這裏插入圖片描述選擇/usr/bin/X :0 -seat seat0 -auth /var/run/lightdm/root/:0這條進程的進程號491,然後
暫停進程
kill -STOP 491
繼續進程
kill -CONT 491


可以在shell裏面,用一句命令實現

ps -ef | grep "/usr/bin/X :0 -seat seat0 -auth /var/run/lightdm/root/:0" | grep -v grep | awk '{print $2}' | xargs kill -STOP -9

也可以用腳本實現

#! /bin/sh  
ID=`ps -ef | grep '/usr/bin/X :0 -seat seat0 -auth /var/run/lightdm/root/:0' | grep -v 'grep' | awk '{print $2}'`  
for pid in $ID  
do  
    kill -STOP -9 $pid  
    echo " kill multimirco pid:$pid"  
done

Tips:
ps -ef : 查看進程
grep ‘multimirco’ 列出進程multimirco的信息
grep -v 'grep' 忽略包含grep的進程
awk '{print $2}'輸出第二列的數據
xargs kill -STOP -9暫停輸入的進程

參考資料

  1. JZ2440(V3)移植QT5.6–圖文教程
  2. Linux編譯移植Qt5的環境_OMAPL138平臺
  3. 移植qt5.5
  4. 移植QT5.7.0到64位fireflyPK3399開發板
  5. Qt上FFTW組件的編譯安裝
  6. QWT編譯與配置-Windows/Linux環境
  7. qwt6.1.0編譯與安裝
  8. Qwt移植到S3C6410
  9. QT編程之FFTW——Linux操作系統
  10. This application failed to start because it could not find or load the Qt platform plugin “linuxfb”
  11. linux暫停一個在運行中的進程
  12. 升級gcc後出現錯誤:/usr/lib/libstdc++.so.6: version `CXXABI_1.3.9’ not found
  13. 如何查找SHELL的進程號並殺死
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章