在ARM64 linux平台运行QT程序

本文详细介绍了如何在Ubuntu系统下,使用Linaro交叉编译工具链为I.MX8QM单片机编译QT5.12.9库。首先,下载并配置QT源码,修改qmake.conf文件以指定编译器路径。接着,通过自定义的配置脚本(myconfigure.sh)生成makefile并进行编译。编译完成后,将QT库安装到指定目录,并在Ubuntu中配置QT交叉编译环境,包括添加QtVersions、g++和gcc编译器以及kits。最后,通过SSH将编译好的QT库传输到I.MX8QM单片机上,编写并运行验证程序,确保QT环境正确配置并能正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以qt5.12.9,单片机为I.MX8QM为例

首先准备交叉编译工具链,链接:Linaro Releases

 本文将工具链放在ubuntu的/opt/路径下

一、交叉编译QT库

1.下载Qt5.12.9源码,下载链接如下:

Index of /new_archive/qt/5.12/5.12.9/single

在Linux下编译一定要选择后缀名为.tar.xz的压缩包,解压缩

tar -xvf qt-everywhere-src-5.12.9.tar.xz

在ubuntu中解压源码,终端进入源码目录

 进入qtbase/mkspecs/目录

cd qtbase/mkspecs/

 复制linux-aarch64-gnu-g++文件夹为myaarch64,因为等会要修改内部文件,备份一下

cp -r linux-aarch64-gnu-g++ myaarch64

在备份文件夹中编辑qmake.conf

cd myaarch64
gedit qmake.conf

编辑内容如下,主要添加/修改了红框部分

#
# qmake configuration for building with aarch64-linux-gnu-g++
#

MAKEFILE_GENERATOR      = UNIX
CONFIG                 += incremental
QMAKE_INCREMENTAL_STYLE = sublib

QT_QPA_DEFAULT_PLATFORM=linuxfb
QMAKE_CFLAGS_RELEASE += -O2 -march=armv8-a -lts
QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv8-a -lts

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

# modifications to g++.conf
QMAKE_CC                = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc
QMAKE_CXX               = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
QMAKE_LINK              = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
QMAKE_LINK_SHLIB        = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++

# modifications to linux.conf
QMAKE_AR                = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-ar cqs
QMAKE_OBJCOPY           = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-objcopy
QMAKE_NM                = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-nm -P
QMAKE_STRIP             = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-strip
load(qt_config)

 回到QT5.12.9源码最顶层目录,输入./configure -help命令,可以查看编译配置选项。在源码最顶层目录,新建文件myconfigure.sh,并添加内容。

-prefix指定编译输出的文件与库的路径

-xplatform指定我们之前修改的qmake.conf文件的目录名称

#! /bin/bash
./configure -prefix /home/fy/qt_aarch64 \
	-opensource -confirm-license \
	-release \
	-strip \
	-shared \
	-xplatform myaarch64 \
	-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 \
	--libpng=qt \
	--libjpeg=qt \
	--sqlite=qt \
	-plugin-sql-sqlite \
	-recheck-all

chmod +x myconfigure.sh给文件添加执行的权限,然后运行./myconfigure.sh,生成makefile文件

chmod +x myconfigure.sh
./myconfigure.sh

如果配置编译选项没有错误,运行了myconfigure.sh文件后没有错误就会出现类似下图的显示

 运行了myconfigure.sh文件后生成了Makefile,就可以执行make命令了

make -j$(nproc)

可能要等很久很久。。。。。。。。

编译结束类似下图

 make完成后就可以执行make install命令了

make install

结束后即可在指定目录-prefix /home/fy/qt_aarch64中看到生成的qt5.14.2文件了

至此交叉编译QT库完成

二、ubuntu中配置QT交叉编译器

在ubuntu安装qt5.12.9,安装流程类似如下:(63条消息) Ubuntu18.04 qt5.14安装_ubuntu18.04安装qt_筱莔梦的博客-优快云博客

打开安装好的qt,点击工具-选项

添加Qt Versions,qmake路径即刚刚交叉编译生成目录的/home/fy/qt_aarch64/bin/qmake,添加完点一下应用

 添加g++与gcc 编译器,名字能区分就行随便给,编译器路径即交叉编译链中g++/gcc路径

/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++

/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc

添加完点一下应用

 添加kits,名称随意能区分别的kits即可。Compiler选择刚刚添加的g++与gcc 编译器,Qt Version也选择刚刚添加的Qt Version

添加完点一下应用

 应用完即可点ok了

三、实机验证

进入IMX8QM开启一个SSH会话,这一步略。可以使用MobaXterm等软件,相信你玩嵌入式linux这里不会有问题

把之前交叉编译好的qt文件/home/fy/qt_aarch64发送到IMX8QM中

 好,接下来在ubuntu中打开qt,新建一个工程,这个参考

(64条消息) Ubuntu18.04 qt5.14安装_ubuntu18.04安装qt_筱莔梦的博客-优快云博客

我们加一行打印

 注意选择编译器

然后只编译(ctrl+B),不执行,因为程序不能在ubuntu运行

找到生成的可执行程序,把它发送到IMX8QM中

 

 运行之前由于要加载qt环境,所以这里写一个qt.sh,内容如下,路径按实际的给

其中,$QT_ROOT/lib/fonts文件夹下放字体,通常可以在电脑的C:\Windows\Fonts中复制字体到这个文件夹

#!/bin/bash
export QT_ROOT=/home/root/qtws/qt_aarch64
export QT_PLUGIN_PATH=$QT_ROOT/plugins
export QML2_IMPORT_PATH=$QT_ROOT/qml
export QT_QPA_FONTDIR=$QT_ROOT/lib/fonts
export QT_QPA_FB_TSLIB=1
export QT_LIBRARY_PATH=$QT_ROOT/lib:$QT_ROOT/plugins/platforms

export LD_LIBRARY_PATH=$QT_LIBRARY_PATH
chmod +x untitled
./untitled

#export FFMPEG_LIBRARY_PATH=/home/root/qtws/ffmpeg5.0.1_gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu/lib
#export LD_LIBRARY_PATH=$QT_LIBRARY_PATH:$FFMPEG_LIBRARY_PATH
#chmod +x fydlw2
#./fydlw2

 写好后给sh执行权限

chmod +x qt.sh

运行qt.sh

./qt.sh

 看到能正常运行,ok,over

后续添加

1.在make install时出现Project ERROR: Unknown module(s) in QT: openglextensions

方法:在上述新建的文件myconfigure.sh中,添加

-skip qtquick3d

参考链接

(63条消息) Qt5.12.11交叉编译+64位ARM_aarch64+全志H5 CortexA53_交叉编译 arm aarch64_Crude2013的博客-优快云博客(63条消息) 自动驾驶开发入门(一)---交叉编译64位Qt5.15 (aarch64)_qt5.15 交叉编译_奔跑吧猴哥的博客-优快云博客

Building on: linux-g++ (x86_64, CPU features: mmx sse sse2) Building for: linux-aarch64-gnu-g++ (arm64, CPU features: neon) Target compiler: gcc 6.3.1 Configuration: cross_compile use_gold_linker compile_examples enable_new_dtags largefile neon precompile_header shared rpath release c++11 c++14 concurrent dbus reduce_exports stl Build options: Mode ................................... release Optimize release build for size ........ no Building shared libraries .............. yes Using C standard ....................... C11 Using C++ standard ..................... C++14 Using ccache ........................... no Using gold linker ...................... yes Using new DTAGS ........................ yes Using precompiled headers .............. yes Using LTCG ............................. no Target compiler supports: NEON ................................. yes Build parts ............................ libs Qt modules and options: Qt Concurrent .......................... yes Qt D-Bus ............................... yes Qt D-Bus directly linked to libdbus .... no Qt Gui ................................. yes Qt Network ............................. yes Qt Sql ................................. yes Qt Testlib ............................. yes Qt Widgets ............................. yes Qt Xml ................................. yes Support enabled for: Using pkg-config ....................... yes udev ................................... no Using system zlib ...................... yes Qt Core: DoubleConversion ....................... yes Using system DoubleConversion ........ no GLib ................................... no iconv .................................. yes ICU .................................... no Tracing backend ........................ Logging backends: journald ............................. no syslog ............................... no slog2 ................................ no Using system PCRE2 ..................... no Qt Network: getifaddrs() ........................... yes IPv6 ifname ............................ yes libproxy ............................... no Linux AF_NETLINK ....................... yes OpenSSL ................................ yes Qt directly linked to OpenSSL ........ no OpenSSL 1.1 ............................ no DTLS ................................... yes SCTP ................................... no Use system proxies ..................... yes Qt Gui: Accessibility .......................... yes FreeType ............................... yes Using system FreeType ................ no HarfBuzz ............................... yes Using system HarfBuzz ................ no Fontconfig ............................. no Image formats: GIF .................................. yes ICO .................................. yes JPEG ................................. yes Using system libjpeg ............... yes PNG .................................. yes Using system libpng ................ no EGL .................................... no OpenVG ................................. no OpenGL: Desktop OpenGL ....................... no OpenGL ES 2.0 ........................ no OpenGL ES 3.0 ........................ no OpenGL ES 3.1 ........................ no OpenGL ES 3.2 ........................ no Vulkan ................................. no Session Management ..................... yes Features used by QPA backends: evdev .................................. yes libinput ............................... no INTEGRITY HID .......................... no mtdev .................................. no tslib .................................. no xkbcommon .............................. no X11 specific: XLib ................................. no EGL on X11 ........................... no QPA backends: DirectFB ............................... no EGLFS .................................. no LinuxFB ................................ yes VNC .................................... yes Mir client ............................. no Qt Sql: SQL item models ........................ yes Qt Widgets: GTK+ ................................... no Styles ................................. Fusion Windows Qt PrintSupport: CUPS ................................... no Qt Sql Drivers: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. no OCI (Oracle) ........................... no ODBC ................................... no PostgreSQL ............................. no SQLite2 ................................ no SQLite ................................. yes Using system provided SQLite ......... no TDS (Sybase) ........................... no Qt Testlib: Tester for item models ................. yes Qt SerialBus: Socket CAN ............................. yes Socket CAN FD .......................... yes Qt QML: QML network support .................... yes QML debugging and profiling support .... yes QML sequence object .................... yes QML list model ......................... yes QML XML http request ................... yes QML Locale ............................. yes QML delegate model ..................... yes Qt Quick: Direct3D 12 ............................ no AnimatedImage item ..................... yes Canvas item ............................ yes Support for Qt Quick Designer .......... yes Flipable item .......................... yes GridView item .......................... yes ListView item .......................... yes TableView item ......................... yes Path support ........................... yes PathView item .......................... yes Positioner items ....................... yes Repeater item .......................... yes ShaderEffect item ...................... yes Sprite item ............................ yes Qt Scxml: ECMAScript data model for QtScxml ...... yes Qt Gamepad: SDL2 ................................... no Qt 3D: Assimp ................................. yes System Assimp .......................... no Output Qt3D Job traces ................. no Output Qt3D GL traces .................. no Use SSE2 instructions .................. no Use AVX2 instructions .................. no Aspects: Render aspect ........................ yes Input aspect ......................... yes Logic aspect ......................... yes Animation aspect ..................... yes Extras aspect ........................ yes Qt 3D Renderers: OpenGL Renderer ........................ yes Qt 3D GeometryLoaders: Autodesk FBX ........................... no Qt Wayland Client ........................ no Qt Wayland Compositor .................... no Qt Bluetooth: BlueZ .................................. no BlueZ Low Energy ....................... no Linux Crypto API ....................... no WinRT Bluetooth API (desktop & UWP) .... no Qt Sensors: sensorfw ............................... no Qt Quick Controls 2: Styles ................................. Default Fusion Imagine Material Universal Qt Quick Templates 2: Hover support .......................... yes Multi-touch support .................... yes Qt Positioning: Gypsy GPS Daemon ....................... no WinRT Geolocation API .................. no Qt Location: Qt.labs.location experimental QML plugin . yes Geoservice plugins: OpenStreetMap ........................ yes HERE ................................. yes Esri ................................. yes Mapbox ............................... yes MapboxGL ............................. no Itemsoverlay ......................... yes QtXmlPatterns: XML schema support ..................... yes Qt Multimedia: ALSA ................................... no GStreamer 1.0 .......................... no GStreamer 0.10 ......................... no Video for Linux ........................ yes OpenAL ................................. no PulseAudio ............................. no Resource Policy (libresourceqt5) ....... no Windows Audio Services ................. no DirectShow ............................. no Windows Media Foundation ............... no Qt Tools: QDoc ................................... no Qt WebEngine: Embedded build ......................... yes Pepper Plugins ......................... no Printing and PDF ....................... no Proprietary Codecs ..................... no Spellchecker ........................... yes Native Spellchecker .................... no WebRTC ................................. no Use System Ninja ....................... no Geolocation ............................ yes WebChannel support ..................... yes Use v8 snapshot ........................ yes Kerberos Authentication ................ no Building v8 snapshot supported ......... yes Use ALSA ............................... no Use PulseAudio ......................... no Optional system libraries used: re2 .................................. no icu .................................. no libwebp, libwebpmux and libwebpdemux . no opus ................................. no ffmpeg ............................... no libvpx ............................... no snappy ............................... no glib ................................. no zlib ................................. yes minizip .............................. no libevent ............................. no jsoncpp .............................. no protobuf ............................. no libxml2 and libxslt .................. no lcms2 ................................ no png .................................. no JPEG ................................. no harfbuzz ............................. no freetype ............................. no x11 .................................. no Required system libraries: fontconfig ........................... no dbus ................................. no nss .................................. no khr .................................. no glibc ................................ yes Required system libraries for qpa-xcb: libdrm ............................... no xcomposite ........................... no xcursor .............................. no xi ................................... no xrandr ............................... no xtst ................................. no Note: Also available for Linux: linux-clang linux-icc
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值