2

I'm developing a C++ program (for a home IoT Project) on Debian 9 that needs to act as an MQTT client. I found paho.mqtt would be helpful in this regard, but none of the on-line documentations to install it worked so far.

Does anyone has any experience on getting paho mqtt c++ client to work on Debian 9? If so, could you help me with the steps I need to do to get it working?

(My Backgroud : I'm pretty comfortable around Linux, kind of OK when it comes to writing code in C or C++, but not that familiar with how c++ compiler works or how to get get C++ header files available for my program in this case)

Thanks in advance!

ChinM
  • 23
  • 1
  • 3
  • Hi and welcome to U&L SE. You state that "none of the on-line documentations to install it worked so far". It would help us help you if you'd tell us which docs you've found, what you've done and what didn't work. Also, are you referring to https://github.com/eclipse/paho.mqtt.cpp? And if so, have you seen the extensive "Building from source" part in https://github.com/eclipse/paho.mqtt.cpp/blob/master/README.md? – Edward Jul 01 '19 at 07:37
  • Hi Edward, yes I tried that document as well. While building the paho.mqtt.cpp packages I run into this error. – ChinM Jul 01 '19 at 20:53
  • mqtttst@tstmqtt:~/paho.mqtt.cpp$ cmake -Bbuild -H. -- The CXX compiler identification is GNU 6.3.0 -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libssl.so;/usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.0j") – ChinM Jul 01 '19 at 20:56
  • CMake Error at /usr/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message): Could NOT find PahoMqttC (missing: PAHO_MQTT_C_LIBRARIES) Call Stack (most recent call first): /usr/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE) cmake/FindPahoMqttC.cmake:22 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) src/CMakeLists.txt:26 (find_package) -- Configuring incomplete, errors occurred! See also "/home/mqtttst/paho.mqtt.cpp/build/CMakeFiles/CMakeOutput.log". – ChinM Jul 01 '19 at 20:56
  • Sorry about the formatting of the above output. I'm new to StackExchange. – ChinM Jul 01 '19 at 20:59
  • OK could you please add that information to the question by [editing](https://unix.stackexchange.com/posts/527810/edit) your question instead of adding it as comments. See my answer below for a successful build. – Edward Jul 02 '19 at 07:40

1 Answers1

3

I installed a stock minimal Debian 9 instance, logged in as a normal user that has sudo rights and did:

sudo apt-get install build-essential gcc make cmake cmake-gui cmake-curses-gui git doxygen graphviz libssl-dev
git clone https://github.com/eclipse/paho.mqtt.c.git
cd paho.mqtt.c
git checkout v1.2.1
cmake -Bbuild -H. -DPAHO_WITH_SSL=ON
sudo cmake --build build/ --target install
sudo ldconfig
cd ..
git clone https://github.com/eclipse/paho.mqtt.cpp
cd paho.mqtt.cpp
cmake -Bbuild -H. -DPAHO_BUILD_DOCUMENTATION=TRUE -DPAHO_BUILD_SAMPLES=TRUE
sudo cmake --build build/ --target install

which gave me a few binaries in /usr/local/bin/. I ran one of those (/usr/local/bin/sync_publish) and got:

/usr/local/bin/sync_publish: error while loading shared libraries: libpaho-mqttpp3.so.1: cannot open shared object file: No such file or directory

I solved that by doing sudo ldconfig.

Edward
  • 2,364
  • 3
  • 16
  • 26
  • Thanks a lot for the for the steps! I could successfully get my C program to connect to the MQTT broker after doing these steps. I will test it on C++ as well and update the thread. – ChinM Jul 03 '19 at 03:43
  • My ubuntu is 20, `paho.mqtt.c` can be installed successfully, but `paho.mqtt.cpp` is failed . whatever, thanks a lot! – Siwei Aug 08 '23 at 05:53