下面是我的项目结构,
root@user-VirtualBox:/home/user/octane_etk_sample-6.0.0.240# ls
bin include paho.mqtt.c speedway_embedded_example.cpp
cap lib paho.mqtt.cpp VERSION
cap_description.in Makefile SCMREV我在项目目录中有paho.mqtt.cpp包,即octane_etk_sample-6.0.0.240,并且我已经安装了https://github.com/eclipse/paho.mqtt.cpp中提到的所有步骤。
现在,我已经在speedway_embedded_example.cpp中包含了MQTTAsync头文件,如下所示:
#include <iostream>
#include <string>
#include <algorithm>
#include <signal.h>
#include <stdio.h>
#include <cstdlib>
#include "ltkcpp.h"
#include "impinj_ltkcpp.h"
#include "time.h"
#include "/home/user/octane_etk_sample-6.0.0.240/paho.mqtt.c/src/MQTTAsync.h"在包含头文件之后,我尝试在public类中建立MQTT客户端连接,
void
CMyApplication::printOneTagReportData (
CTagReportData * pTagReportData)
{
string address = "tcp://mqtt1.mindlogic.com:1883";
cout << "OK\n" << address;
mqtt::async_client cli(address, "", 120, "data-persist");
}当我尝试制作一个speedway_embedded_example文件时,我得到了下面的错误,
root@user-VirtualBox:/home/mindlogic/octane_etk_sample-6.0.0.240# make
mkdir -p ./bin
g++ \
-m32 -Wno-write-strings \
-Iinclude \
speedway_embedded_example.cpp \
-Llib -lltkcpp_x86 -lltkcppimpinj_x86 -lxml2_x86 \
-L/usr/bin -ldl -lssl -lcrypto \
-o bin/speedwayr_x86
speedway_embedded_example.cpp: In member function ‘void CMyApplication::printOneTagReportData(LLRP::CTagReportData*)’:
speedway_embedded_example.cpp:1650:4: error: ‘mqtt’ has not been declared
mqtt::async_client cli(address, "", 120, "data-persist");在上面的场景中,有没有人能帮我建立一个客户端连接?
发布于 2020-04-15 03:15:59
您包括了C库,它没有名称空间。
您(可能)想要C++库。
https://github.com/eclipse/paho.mqtt.cpp
或者更好的是,因为包含了嵌入的标记,所以您可能希望使用
https://github.com/eclipse/paho.mqtt.embedded-c
它嵌入了C和C++的代码。您应该使用您正在使用的库提供的示例代码。
https://stackoverflow.com/questions/61213808
复制相似问题