3

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!

6
  • 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 github.com/eclipse/paho.mqtt.cpp? And if so, have you seen the extensive "Building from source" part in github.com/eclipse/paho.mqtt.cpp/blob/master/README.md? Commented Jul 1, 2019 at 7:37
  • Hi Edward, yes I tried that document as well. While building the paho.mqtt.cpp packages I run into this error. Commented Jul 1, 2019 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") Commented Jul 1, 2019 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". Commented Jul 1, 2019 at 20:56
  • Sorry about the formatting of the above output. I'm new to StackExchange. Commented Jul 1, 2019 at 20:59

1 Answer 1

4

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.

2
  • 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. Commented Jul 3, 2019 at 3:43
  • My ubuntu is 20, paho.mqtt.c can be installed successfully, but paho.mqtt.cpp is failed . whatever, thanks a lot! Commented Aug 8, 2023 at 5:53

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.