记困扰了两天的QtMqtt库交叉编译过程

本文详细介绍了如何下载QtMqtt交叉编译包,进行交叉编译,并将编译后的动态链接库应用于QT项目。步骤包括:下载源码、配置编译、复制头文件和库文件、修改工程配置以及使用QMqttClient连接MQTT服务器的示例代码。通过此教程,开发者可以成功集成并使用QtMqtt库进行MQTT通信。

一、下载QtMqtt交叉编译包

https://github.com/qt/qtmqtt

本文用的是5.12版本

二、交叉编译QtMqtt

使用QtCreator打开下载的交叉编译包在这里插入图片描述
先编译一下
进入这个文件夹,复制一下的这些头文件
在这里插入图片描述
然后进入工程目录的编译文件夹中Debug或者Release都行
复制一份到这里
在这里插入图片描述
然后QtMqtt文件夹里面也复制一份
最后编译一次
在这里插入图片描述

三、使用编译成功的QtMqtt动态链接库

进入Debug或者Release中的lib文件夹复制下面的文件
在这里插入图片描述
到你自己的QT项目
建立这两个文件夹
在这里插入图片描述
把刚刚复制的那几个文件复制进lib里面去
在这里插入图片描述
然后复制之前那些头文件进include/QtMqtt
在这里插入图片描述

四、引入库

在工程的pro文件中这里需要加一个network
在这里插入图片描述
添加QtMqtt库

win32:CONFIG(release, debug|release): LIBS += 
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
### 下载适用于 Qt 5.11.2 的交叉编译环境 为了设置适用于 Qt 5.11.2 的交叉编译环境,需遵循一系列特定的操作来确保整个过程顺畅无误。 #### 获取源码包 首先,获取适合于跨平台使用的 Qt 源代码压缩包。对于指定版本 Qt 5.11.2 来说,应当访问官方资源或其他可信站点下载对应版本的 `qt-everywhere` 压缩文件,例如 `qt-everywhere-src-5.11.2.tar.xz`[^1]。 ```bash wget http://download.qt.io/archive/qt/5.11/5.11.2/single/qt-everywhere-src-5.11.2.tar.xz tar xf qt-everywhere-src-5.11.2.tar.xz cd qt-everywhere-src-5.11.2 ``` #### 配置交叉编译工具链 当准备构建针对不同架构的应用程序时,重要的是调整 Makefile 文件中的头文件路径,防止默认链接到主机系统的标准位置 `/usr/include/`,这可能会引起冲突或不兼容问题[^2]。因此,在配置阶段应明确指明目标平台的相关细节以及所依赖的位置。 假设已经拥有一个合适的 GCC 工具链用于 ARM 架构,则可以在运行 configure 脚本之前通过设定环境变量的方式引入必要的外部依赖项: ```bash export PATH=/path/to/toolchain/bin:$PATH export PKG_CONFIG_PATH=/path/to/sysroot/usr/lib/pkgconfig ./configure -xplatform linux-arm-gnueabi-g++ ... ``` 这里 `-xplatform` 参数告知 Qt 使用哪个预定义的目标平台规格;而具体的编译器前缀(如 `arm-linux-gnueabihf-`)则取决于实际选用的工具链。 #### 解决 freetype 的问题 如果遇到与 FreeType 字体渲染有关联的错误提示,可以按照建议的方法把交叉编译后的 FreeType 安装目录下的 bin 子目录添加至当前 shell session 的 `$PATH` 变量中去,从而让后续命令能够找到所需的可执行文件[^3]。 ```bash export PATH=$freetype_prefix/bin:$PATH ``` #### 处理潜在的临时文件夹缺失问题 有时在 Windows 平台上进行软件安装过程中会遭遇由于系统临时文件夹路径未被正确识别而导致失败的情况。此时可以通过安装并适当配置 Rtools 来修正这一状况,因为其不仅提供了 MinGW 和 MSYS 等组件支持 GNU 编程工具集,还帮助解决了某些情况下因缺少合适的工作区造成的困扰[^4]。 综上所述,以上步骤涵盖了从下载所需材料直至完成初步搭建的一系列指导方针,旨在协助开发者顺利完成基于 Qt 5.11.2 版本的嵌入式 Linux 开发工作。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值