1

I need to use mqtt broker in a project of mine. But i felt there is a huge lack of documentation. Some of the available example codes i found didn't really work for me. Followed this example, but got compilation error

[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

Also tried to look into the sample codes given in the mqtt archive but make command failed to compile them. So tried to compile the sample files separately which succeeded but while running it gives buffer overflow and mosquito terminal output is

[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.

It would be great if somebody has worked with mqtt before and can share a basic code. Thanks. I have pushed all the files i tried in github, you can have a look here.

codename_subho
  • 456
  • 8
  • 22
  • I'm playing with Mosquitto as well and managed to make the examples work through the following steps: - installed the Ubuntu repository version of the broker as described in the [Mosquitto download page](http://mosquitto.org/download/) - downloaded the mosquitto source code and launched the `make` on the uncompressed folder - launched `make` inside the tempcov example folder For me the example compiled and actually worked with the broker installed separately. – rustyrick Apr 11 '15 at 15:34
  • However the other [example](http://www.disk91.com/2013/technology/programming/mosquitto-c-sample-code-to-publish-message/) you mentioned is compiling but not working for me. I believe there's an issue on `connect_async` as I'm getting a return code != from 0 when trying to connect to the broker... – rustyrick Apr 11 '15 at 15:35

1 Answers1

0

I have the same problem from time to time. Maybe the late answer helps another one, too. Ubuntu has a rather old version of mosquitto. In the meantime it became an eclipse project and some things changed.

This problem occurs, if the mosquitto package of a linux distribution is installed, where the library files go into /usr/lib. For having the header files the source code has to be downloaded and if make install is called, the new library with changed function names or namespace go into /usr/local/lib. Hence the wrong library is linked.

Ernie Mur
  • 481
  • 3
  • 18
  • solution: after make; su; make install erase /usr/lib/mosquitto* in order that /usr/local/lib/mosquitto is used – Ernie Mur Mar 16 '16 at 01:38