CPP MQTT Broker代码不工作
CPP MQTT Broker code not working
我需要在我的一个项目中使用mqtt broker。但我觉得文件非常缺乏。我发现的一些可用的示例代码并不适合我。遵循这个示例,但出现了编译错误
[subho@localhost] taboo $ g++ mqtt.cpp -o a
/tmp/ccg9xcFV.o: In function `myMosq::myMosq(char const*, char const*, char const*, int)':
mqtt.cpp:(.text+0x31): undefined reference to `mosqpp::mosquittopp::mosquittopp(char const*, bool)'
mqtt.cpp:(.text+0x41): undefined reference to `mosqpp::lib_init()'
mqtt.cpp:(.text+0x9c): undefined reference to `mosqpp::mosquittopp::connect_async(char const*, int, int)'
mqtt.cpp:(.text+0xa8): undefined reference to `mosqpp::mosquittopp::loop_start()'
mqtt.cpp:(.text+0xb9): undefined reference to `mosqpp::mosquittopp::~mosquittopp()'
/tmp/ccg9xcFV.o: In function `myMosq::~myMosq()':
mqtt.cpp:(.text+0xf5): undefined reference to `mosqpp::mosquittopp::loop_stop(bool)'
mqtt.cpp:(.text+0xfa): undefined reference to `mosqpp::lib_cleanup()'
mqtt.cpp:(.text+0x106): undefined reference to `mosqpp::mosquittopp::~mosquittopp()'
mqtt.cpp:(.text+0x12c): undefined reference to `mosqpp::mosquittopp::~mosquittopp()'
/tmp/ccg9xcFV.o: In function `myMosq::send_message(char const*)':
mqtt.cpp:(.text+0x1b0): undefined reference to `mosqpp::mosquittopp::publish(int*, char const*, int, void const*, int, bool)'
/tmp/ccg9xcFV.o:(.rodata._ZTI6myMosq[_ZTI6myMosq]+0x10): undefined reference to `typeinfo for mosqpp::mosquittopp'
collect2: error: ld returned 1 exit status
还试图查看mqtt归档中给出的示例代码,但make命令未能编译它们。因此,尝试单独编译样本文件,成功了,但在运行时出现缓冲区溢出,蚊式终端输出为
[subho@localhost] Web_App $ (master) mosquitto
1426996368: mosquitto version 1.3.5 (build date 2014-10-16 10:32:53+0000) starting
1426996368: Using default config.
1426996368: Opening ipv4 listen socket on port 1883.
1426996368: Opening ipv6 listen socket on port 1883.
1426996369: New connection from 127.0.0.1 on port 1883.
1426996369: New client connected from 127.0.0.1 as tempconv (c1, k60).
1426996369: Socket error on client tempconv, disconnecting.
1426997037: New connection from 127.0.0.1 on port 1883.
1426997037: New client connected from 127.0.0.1 as tempconv (c1, k60).
1426997037: Socket error on client tempconv, disconnecting.
1426997314: New connection from 127.0.0.1 on port 1883.
1426997314: New client connected from 127.0.0.1 as tempconv (c1, k60).
1426997314: Socket error on client tempconv, disconnecting.
如果有人以前使用过mqtt,并且可以共享一个基本代码,那就太好了。谢谢我已经推送了我在github中尝试的所有文件,你可以在这里看看。
我不时遇到同样的问题。也许迟来的答案对另一个答案也有帮助。Ubuntu有一个相当古老的蚊子版本。与此同时,它变成了一个eclipse项目,有些事情发生了变化。
如果安装了linux发行版的mosquitto包,库文件将进入/usr/lib,则会出现此问题。为了获得头文件,必须下载源代码,如果调用make-install,则更改了函数名或命名空间的新库将进入/usr/local/lib。因此链接了错误的库。
相关文章:
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 当我从下面的代码中删除关键字 virtual 时,它可以正常工作,否则会出现错误。在这里"virtual"字的意义是什么?
- C++代码在台式机上工作正常,但在笔记本电脑上则不行
- 我想使用此代码单击某个特定窗口,但它无法正常工作
- C++代码停止工作错误使用cout内部函数
- 我的代码无法正常工作。谁能指出错误?
- 有人可以详细解释这个回文代码是如何工作的吗?
- 代码在 CodeSignal 中工作不正确。不确定这是否是我的代码缺陷
- 代码在Visual Studio 2017中不起作用,但在VS代码中工作
- 以下代码如何工作以每次为唯一调用堆栈唯一实例化模板函数?
- 添加新行时工作代码引发异常.调试技巧?
- 一个非常简单的win32套接字代码,但工作错误
- 需要WXLISTCTRL的代码更改为虚拟样式WXListCtrl的工作代码
- C++ / CannyEdgeDetection.exe 已停止工作 代码块 /OpenCV 错误:断言失败
- C //尝试重写一个工作代码以包括我的功能
- 如何在不保存文件的情况下制作打印屏幕并将其发送到FTP服务器?我的工作代码将文件保存到HDD
- 如何在不破坏当前工作代码的情况下添加小数
- 无法理解工作代码和损坏代码之间的区别
- .exe已停止工作代码块 CPP
- rapidjson:用于从文件中读取文档的工作代码