sony / nmos-cpp

An NMOS (Networked Media Open Specifications) Registry and Node in C++ (IS-04, IS-05)
Apache License 2.0
138 stars 80 forks source link

can't import paho-mqtt-cpp into project #178

Open desimetallica opened 3 years ago

desimetallica commented 3 years ago

Hello everyone, I'm trying to do some test with mqtt but I'm encountering some issues with conan and cmake that are both pretty new to me. I've added paho-mqtt-cpp/1.2.0 to my conanfile.txt (also with option paho-mqtt-cpp:shared=False)

I've created a copy of nmos-cpp-node called nmos-cpp-receiver and added the modification on CMakeLists.txt to create the executable.

I've added on nmos-cpp-receiver/node_implementation.cpp:

include <mqtt/client.h>

and just a simple: mqtt::client mqttclient(impl::broker::SERVER_ADDRESS, impl::broker::CLIENT_ID);

But I'm getting some undefined references when I try to clean/build: [build] CMakeFiles/nmos-cpp-receiver.dir/nmos-cpp-receiver/node_implementation.cpp.o: In function __static_initialization_and_destruction_0(int, int)': [build] /workspaces/nmos-cpp/Development/nmos-cpp-receiver/node_implementation.cpp:112: undefined reference tomqtt::client::client(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' [build] CMakeFiles/nmos-cpp-receiver.dir/nmos-cpp-receiver/nodeimplementation.cpp.o: In function `mqtt::client::~client()': [build] /home/vscode/.conan/data/paho-mqtt-cpp/1.2.0///package/0d29a7c828f525fa48af40cddee0b1bf7a0b6dd2/include/mqtt/client.h:173: undefined reference to `vtable for mqtt::client' [build] /home/vscode/.conan/data/paho-mqtt-cpp/1.2.0//_/package/0d29a7c828f525fa48af40cddee0b1bf7a0b6dd2/include/mqtt/client.h:173: undefined reference to `mqtt::async_client::~async_client()'

I'm doing something wrong here but I'm not understanding what. Conan should take care about lib and dependencies for me right? Sorry maybe I'm missing something really dumb, but I'm not getting what is the problem here.

alanb-sony commented 3 years ago

conan only downloads/builds the library for you, you still need to link it, e.g. in https://github.com/sony/nmos-cpp/blob/cdc16d48e4bf5e6e6f808e90cbf75384d6efe6b5/Development/CMakeLists.txt#L42

desimetallica commented 3 years ago

Hello Alan, many thanks for your answer! This is clear now! In order to test a little bit more on cmake stuff I've explored the lines related to mqtt library vars produced into FindPahoMqttCpp.cmake and Findeclipse-paho-mqtt-c.cmake and i've added it into my CMakeLists.txt:

target_link_libraries( nmos-cpp-receiver nmos-cpp_static ${CPPRESTSDK_TARGET} ${PLATFORM_LIBS} ${Boost_LIBRARIES} ${eclipse-paho-mqtt-c_LIBRARIES} ${PahoMqttCpp_LIBRARIES} )

I've also added into NmosCppCommon.cmake:

include_directories( ... ${PahoMqttCpp_INCLUDE_DIRS} ${eclipse-paho-mqtt-c_INCLUDE_DIRS} )

I'm still getting the same error. I've explored some more on FindPahoMqttCpp.cmake and i've tried to add:

target_link_libraries( nmos-cpp-receiver nmos-cpp_static ${CPPRESTSDK_TARGET} ${PLATFORM_LIBS} ${Boost_LIBRARIES} ${PahoMqttCpp_paho-mqttpp3-static_LIBS} )

But I'm still getting the same error. I don't know what to do honestly... I forgot to specify: I'm running on ubuntu 18.04 and vscode insiders with cmake tools add-on. Many thanks for your support...

alanb-sony commented 3 years ago

do you have a find_package call for paho?

desimetallica commented 3 years ago

Oh, that solved my problem... many thanks Alan! You can close this issue I think