(mqtt學習2)編譯安裝paho

1,源碼下載:

https://github.com/eclipse/paho.mqtt.c

解壓:

guoyanzhang@debian:~/test$ unzip paho.mqtt.c-master.zip

2,安裝編譯用的庫

guoyanzhang@debian:~/test/paho.mqtt.c-master$ sudo apt-get install build-essential gcc make cmake cmake-gui cmake-curses-gui
guoyanzhang@debian:~/test/paho.mqtt.c-master$ sudo apt-get install fakeroot fakeroot devscripts dh-make lsb-release
guoyanzhang@debian:~/test/paho.mqtt.c-master$ sudo apt-get install libssl-dev
guoyanzhang@debian:~/test/paho.mqtt.c-master$ sudo apt-get install doxygen graphviz

3,編譯

guoyanzhang@debian:~/test/paho.mqtt.c-master$ make
guoyanzhang@debian:~/test/paho.mqtt.c-master$ sudo make install
guoyanzhang@debian:~/test/paho.mqtt.c-master$ make html

4,把頭文件拷貝到自己要用的地方(這步根據自己的需要選擇做)

guoyanzhang@debian:~/test$ cp paho.mqtt.c-master/src/MQTTAsync.h mqtt_h/
guoyanzhang@debian:~/test$ cp paho.mqtt.c-master/src/MQTTClientPersistence.h mqtt_h/
guoyanzhang@debian:~/test$ cp paho.mqtt.c-master/src/MQTTProperties.h mqtt_h/
guoyanzhang@debian:~/test$ cp paho.mqtt.c-master/src/MQTTReasonCodes.h mqtt_h/
guoyanzhang@debian:~/test$ cp paho.mqtt.c-master/src/MQTTSubscribeOpts.h mqtt_h/

5,編譯的時候要用-lpaho-mqtt3a

The Paho C client comprises four shared libraries:

libmqttv3a.so - asynchronous (MQTTAsync)
libmqttv3as.so - asynchronous with SSL (MQTTAsync)
libmqttv3c.so - "classic" / synchronous (MQTTClient)
libmqttv3cs.so - "classic" / synchronous with SSL (MQTTClient)

3a是異步,3as是帶ssl的異步,3c是同步,3cs是帶ssl的同步。

paho是分異步函數和同步函數的,異步函數是非阻塞的,就是把消息發到broker,函數會立即返回,但是消息並未被執行,而是加入一個隊列,等待執行,同步函數是阻塞的,等到消息被執行才返回。異步函數也可以加一些其它的參數變成同步阻塞,總體來說,異步函數包含同步函數。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章