【问题标题】:CPP MQTT Broker code not workingCPP MQTT 代理代码不起作用
【发布时间】:2015-03-22 04:23:31
【问题描述】:

我需要在我的项目中使用mqtt broker。但是我觉得文档非常缺乏。我发现的一些可用示例代码对我来说并不适用。关注这个example,但是编译出错

[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 archive 中给出的示例代码,但 make 命令无法编译它们。所以尝试单独编译成功的示例文件,但在运行时它会给出buffer overflow,并且蚊子终端输出是

[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中尝试过的文件,你可以看看here

【问题讨论】:

  • 我也在玩 Mosquitto,并设法通过以下步骤使示例工作: - 安装了 Mosquitto download page 中描述的代理的 Ubuntu 存储库版本 - 下载了 mosquitto 源代码并在未压缩的文件夹中启动 make - 在 tempcov 示例文件夹中启动 make 对我来说,该示例已编译并实际与单独安装的代理一起使用。
  • 但是您提到的另一个example 正在编译但不适用于我。我相信connect_async 存在问题,因为我在尝试连接到代理时收到返回码!= 从 0...

标签: c++ mqtt mosquitto libmosquitto


【解决方案1】:

我时常遇到同样的问题。也许迟到的答案也可以帮助另一个人。 Ubuntu 有一个相当旧的 mosquitto 版本。与此同时,它变成了一个 Eclipse 项目,并且发生了一些变化。

如果安装了 linux 发行版的 mosquitto 包,则会出现此问题,其中库文件进入 /usr/lib。为了获得头文件,必须下载源代码,并且如果调用 make install,具有更改的函数名称或命名空间的新库将进入 /usr/local/lib。 因此链接了错误的库。

【讨论】:

  • 解决方法:make后;苏; make install erase /usr/lib/mosquitto* 以便使用 /usr/local/lib/mosquitto
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-06
  • 2018-07-28
相关资源
最近更新 更多