1

I am getting the following errors when I try to compile one of the example:

main.cpp:8:undefined reference to `mosqpp::lib_init()'
main.cpp:13: undefined reference to `mosqpp::mosquittopp::loop(int, int)'
main.cpp:15: undefined reference to `mosqpp::mosquittopp::reconnect()'
temperature_conversion.o: In function `mqtt_tempconv':
temperature_conversion.cpp:7: undefined reference to `mosqpp::mosquittopp::mosquittopp(char const*, bool)'
temperature_conversion.cpp:13: undefined reference to `mosqpp::mosquittopp::connect(char const*, int, int)'
temperature_conversion.cpp:7: undefined reference to `mosqpp::mosquittopp::~mosquittopp()'
temperature_conversion.o: In function `mqtt_tempconv::on_connect(int)':
temperature_conversion.cpp:21: undefined reference to `mosqpp::mosquittopp::subscribe(int*, char const*, int)'
temperature_conversion.o: In function `mqtt_tempconv::on_message(mosquitto_message const*)':
temperature_conversion.cpp:37: undefined reference to `mosqpp::mosquittopp::publish(int*, char const*, int, void const*, int, bool)'

Please help

hardillb
  • 54,545
  • 11
  • 67
  • 105
pratap
  • 11
  • 1
  • 2
  • 1
    Please show your compile and link commands. Also see [How to compile using libmosquitto](https://stackoverflow.com/q/19707329/608639) – jww Mar 19 '19 at 06:37

2 Answers2

2

Your question doesn't give much detail - you should describe how you've gone about it as well as what the problem is.

Having said that, it looks like you haven't linked against the library.

If you are compiling like this:

g++ main.o temperature_conversion.o -o temperature_conversion 

Then you need to link against the library:

g++ main.o temperature_conversion.o -o temperature_conversion -lmosquittopp

I'm assuming it is already installed.

ralight
  • 11,033
  • 3
  • 49
  • 59
1

locate libmosquittopp.so can help you understanding the directory to give to g++ as -L parameter.

g++ main.o temperature_conversion.o -o temperature_conversion -lmosquittopp \
    -L$(locate libmosquitto.so | tail -n 1 | xargs -n1 dirname)
fiorentinoing
  • 948
  • 12
  • 20