You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编译C++ Paho MQTT代码报错:找不到Paho MQTT C库

Fix: "Could not find Paho MQTT C library" when compiling Paho MQTT C++ on Ubuntu 16.04

It seems your Paho MQTT C library is installed properly, but the CMake build system for the C++ library can't locate it. This is a common hiccup on Ubuntu 16.04, usually tied to dynamic link cache updates or CMake's default search path limitations. Here are targeted fixes to resolve this:

When you install libraries to /usr/local/lib (the default location for sudo make install), Ubuntu 16.04 doesn't automatically update its dynamic linker cache. This means the system (and CMake) might not recognize the newly installed Paho C library. Run this command first:

sudo ldconfig

Then try rebuilding the C++ library again, clearing old build artifacts to avoid conflicts:

cd ~/Paho_MQTT/paho_cpp/paho.mqtt.cpp/build
rm -rf *
cmake ..
make

2. Manually specify the Paho C library path to CMake

If the first step doesn't work, CMake might not be checking /usr/local by default. You can explicitly point it to the C library's headers and binaries:

First, confirm the default installation paths (these are correct if you used the standard make install):

  • Header files: /usr/local/include
  • Library file: /usr/local/lib/libpaho-mqtt3a.so (shared library) or /usr/local/lib/libpaho-mqtt3a.a (static library)

Run CMake with these paths specified:

cd ~/Paho_MQTT/paho_cpp/paho.mqtt.cpp/build
rm -rf *
cmake -DPAHO_MQTT_C_INCLUDE_DIR=/usr/local/include -DPAHO_MQTT_C_LIBRARY=/usr/local/lib/libpaho-mqtt3a.so ..
make

If you built the static version of the Paho C library, replace .so with .a in the library path.

3. Verify shared library support in Paho C library (optional)

If issues persist, check if you enabled shared library builds when compiling the Paho C library—the C++ library typically expects this by default:

  1. Navigate back to your Paho C build directory:
    cd ~/Paho_MQTT/paho_c/paho.mqtt.c/build
    
  2. Reopen the CMake configuration:
    ccmake ..
    
  3. Use arrow keys to navigate to BUILD_SHARED_LIBS and toggle it to ON (press Enter to change the value).
  4. Recompile and reinstall the C library:
    make
    sudo make install
    sudo ldconfig
    
  5. Return to the C++ library build directory and try compiling again.

内容的提问来源于stack exchange,提问作者Salman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:14:56