paho-mqtt开发环境搭建
paho.mqtt.cpp需要依赖openssl、paho.mqtt.c两个库
安装openssl
// 一般系统会预安装
sudo apt install libssl-dev
编译安装paho.mqtt.c
git clone https://github.com/eclipse/paho.mqtt.c.git
cmake . -Bbuild -DPAHO_WITH_SSL=ON -DPAHO_BUILD_SHARED=OFF -DPAHO_BUILD_STATIC=ON -DPAHO_ENABLE_TESTING=OFF
cd build
make -j8
sudo make install
sudo ldconfig
编译安装paho.mqtt.cpp
git clone https://github.com/eclipse/paho.mqtt.cpp
// PAHO_WITH_SSL默认为TRUE
// 好像可以用PAHO_WITH_MQTT_C=ON C++可以拉子仓编C库,不用上面一步操作
cmake . -Bbuild -DPAHO_WITH_SSL=ON -DPAHO_BUILD_SHARED=OFF -DPAHO_BUILD_STATIC=ON
cd build
make -j8
sudo make install
sudo ldconfig
安装测试broker
sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients // 测试工具mosquitto_pub mosquitto_sub
环境测试
mosquitto_pub -h localhost -t test/topic -m "hello"
mosquitto_sub -h localhost -t test/topic