QT-MQTT交叉编译(目标机环境:Arm-32位)

一、目标机环境

Linux version 5.10.66  (arm-rockchip830-linux-uclibcgnueabihf-gcc (crosstool-NG 1.24.0)

二、QT-MQTT源码下载

GitHub - qt/qtmqtt: Qt Module to implement MQTT protocol version 3.1 and 3.1.1 http://mqtt.org/Qt Module to implement MQTT protocol version 3.1 and 3.1.1 http://mqtt.org/ - qt/qtmqtticon-default.png?t=N7T8https://github.com/qt/qtmqtt

三、交叉编译

根据本地交叉编译的QT环境来选择QT-MQTT的版本,笔者用的是QT 5.12.9源码库,所以直接选了QT-MQTT 5.15.2,而不是QT-MQTT 6+版本。

$ cd qtmqtt/
$ git checkout v5.15.2

打开 qtmqtt.pro,如果之前交叉编译过QT应用,QT IDE里的编译配置都是正常的。如下图所示:

配置好你想要的build目录后,直接编译。

可能是版本不完全兼容的缘故,编译过程中出现两个语法错误,改之即可:

四、布署QT-MQTT

       常用的有三种方式:第一种是直接将QT-MQTT源码植入目标工程,第二种是以模块(Module)的形式将QT-MQTT的头文件及库文件部署至QT源码的交叉编译目录中,第三种是在目标工程中添加QT-MQTT的头文件和库文件。

我们这里使用第二种方式,方便多个目标工程共用。

1.头文件(include)

将qtmqtt/src/mqtt目录内的头文件拷贝至QT源码的交叉编译目录的include下,后者如qt-5.12.9/arm-qt/include/QtMqtt, QtMqtt目录需要自己新建。如下图所示:

注意:最好不要用QT-MQTT编译输出目录下的头文件,理由就不多说了。

2.库文件(lib/so)

将QT-MQTT编译输出目录lib下的四个so文件拷贝至QT源码的交叉编译目录的lib下,后者如qt-5.12.9/arm-qt/lib。如下图所示:

3.模块配置文件(pri)

       将QT-MQTT编译输出目录mkspecs\modules下的pri文件(qt_lib_mqtt.pri)拷贝至QT源码的交叉编译目录modules下,后者如qt-5.12.9/arm-qt/mkspecs/modules。如下图所示:

五、测试QT-MQTT

目录工程配置文件(pro)引入mqtt模块

QT += mqtt

头文件包含

#include "qmqttclient.h"

如下图所示: 

六、移植QT-MQTT至嵌入式设备(ARM+LINUX)

将QT-MQTT编译输出目录lib下的四个so文件拷贝至嵌入式设备的lib下,后者必须位于系统环境变量下。可用env命令查看环境变量,如下图所示:

七、开发环境更换电脑后的编译错误

主要原因:模块配置文件(qt_lib_mqtt.pri)中的路径配置,是跟编译QT-MQTT的工程环境绑定了,改至布署后的目录环境即可,如下图所示:

修改前:

QT_MODULE_BIN_BASE = /home/xxx/Desktop/project/build/build-qtmqtt-Arm_Qt5_12_9-Release/bin
QT_MODULE_INCLUDE_BASE = /home/xxx/Desktop/project/build/build-qtmqtt-Arm_Qt5_12_9-Release/include
QT_MODULE_LIB_BASE = /home/xxx/Desktop/project/build/build-qtmqtt-Arm_Qt5_12_9-Release/lib
QT_MODULE_HOST_LIB_BASE = /home/xxx/Desktop/project/build/build-qtmqtt-Arm_Qt5_12_9-Release/lib
include(/home/xxx/Desktop/project/build/build-qtmqtt-Arm_Qt5_12_9-Release/mkspecs/modules-inst/qt_lib_mqtt.pri)
QT.mqtt.priority = 1
include(/home/xxx/Desktop/project/build/build-qtmqtt-Arm_Qt5_12_9-Release/mkspecs/modules-inst/qt_lib_mqtt_private.pri)
QT.mqtt_private.priority = 1

修改后:

QT.mqtt.VERSION = 5.12.9
QT.mqtt.name = mqtt
QT.mqtt.module = Qt5Mqtt
QT.mqtt.libs = $$QT_MODULE_LIB_BASE
QT.mqtt.includes = $$QT_MODULE_INCLUDE_BASE $$QT_MODULE_INCLUDE_BASE/QtMqtt

修改依据:参数同级目录的其它pri文件即可,如qt_lib_sql.pri内容如下:

QT.sql.VERSION = 5.12.9
QT.sql.name = QtSql
QT.sql.module = Qt5Sql
QT.sql.libs = $$QT_MODULE_LIB_BASE
QT.sql.includes = $$QT_MODULE_INCLUDE_BASE $$QT_MODULE_INCLUDE_BASE/QtSql
QT.sql.frameworks =
QT.sql.bins = $$QT_MODULE_BIN_BASE
QT.sql.plugin_types = sqldrivers
QT.sql.depends = core
QT.sql.uses =
QT.sql.module_config = v2
QT.sql.DEFINES = QT_SQL_LIB
QT.sql.enabled_features = sqlmodel
QT.sql.disabled_features =
QT_CONFIG +=
QT_MODULES += sql

  • 22
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值