Reputation: 387
I'm a bit new to CMake
. So this might be a noob question..
I'm trying to build cpp project with CMake
. I would like my program to publish to a mqtt broker. I'm running on Linux.
So I installed https://github.com/eclipse/paho.mqtt.cpp
and the corresponding c project by doing (side by side)
$ git clone https://github.com/eclipse/paho.mqtt.c.git
$ cd paho.mqtt.c
$ git checkout v1.3.1
$ cmake -Bbuild -H. -DPAHO_WITH_SSL=ON -DPAHO_ENABLE_TESTING=OFF
$ sudo cmake --build build/ --target install
$ sudo ldconfig
as per the documentation and then doing.
$ git clone https://github.com/eclipse/paho.mqtt.cpp
$ mkdir build
$ cd build
$ cmake ../
$ make
$ sudo make install
which all worked fine without any errors.. Now what do i put in my own cmakelists file in my own project that I can use the libraries? So I can do.
#include "mqtt/async_client.h"
int main(int argc, char *argv[]){
std::cout << "Hello World!" << std::endl;
mqtt::async_client cli(DFLT_ADDRESS, "", 120, PERSIST_DIR);
return 0;
}
I tried a simple.
cmake_minimum_required(VERSION 2.8.9)
project (hello)
find_package(PahoMqttCpp REQUIRED)
add_executable(hello helloworld.cpp)
target_link_libraries(hello ${PAHO_CPP_LIB})
But that does not seem to be enough.. I get
helloworld.cpp:(.text+0xd3): undefined reference to `mqtt::async_client::~async_client()'
Any help would be appreciated.
Upvotes: 3
Views: 2114
Reputation: 387
Okay, after some digging, I found the correct thing to write is:
target_link_libraries(hello paho-mqttpp3 paho-mqtt3as)
Upvotes: 5