2021年1月21日 星期四

樹莓派學習筆記 : 編譯 MQTT 套件 mosquitto 原始碼問題

今天繼續讀朱克剛寫的 "AIOT與OpenCV實戰應用:Python、樹莓派、物聯網與機器視覺" 的 MQTT 部分, 書中使用的是 mosquitto 套件, 可用 pip 安裝或從 GitHub 下載原始碼自行編譯, 作者建議自行編譯, 因為可以開啟 websockets 功能以便透過網頁介面進行 MQTT 操作. 

我照作者建議下載原始碼自行編譯, 但編譯過程發生錯誤, 試圖爬文解決未果, 暫且將過程記錄如下, 等待找到解決方案再來重新編譯, mosquitto 套件原始碼下載網址如下 : 


開啟樹莓派的 Chromium 瀏覽器連線上面的 GitHub 網址下載原始碼 zip 壓縮檔 :




下載的壓縮檔 mosquitto-master.zip 預設放在使用者目錄下的 Downloads 資料夾下面, 可使用 unzip 程式解壓縮, 它會建立 mosquitto-master 子目錄來存放這些原始碼 :

pi@raspberrypi:~ $ cd Downloads   
pi@raspberrypi:~/Downloads $ unzip mosquitto-master.zip    
pi@raspberrypi:~/Downloads $ cd mosquitto-master    


1. 編輯 config.mk 檔開啟 websockets 功能 : 

用 nano 編輯 config.mk 檔, 將其中的 WITH_WEBSOCKETS 從原先的 no 改成 yes : 

pi@raspberrypi:~/Downloads/mosquitto-master $ nano config.mk    




這就是自行編譯的好處 : 能在編譯前進行細部功能設定. 


2. 更新套件清單 :

此步驟是必要的, 否則後續下載安裝五套件時可能會因為找不到套件而安裝失敗 : 

sudo apt-get update

pi@raspberrypi:~/Downloads/mosquitto-master $ sudo apt-get update   
下載:1 http://archive.raspberrypi.org/debian stretch InRelease [25.3 kB]  
下載:2 http://archive.raspberrypi.org/debian stretch/main armhf Packages [192 kB]
下載:3 http://raspbian.raspberrypi.org/raspbian stretch InRelease [15.0 kB]
下載:4 http://raspbian.raspberrypi.org/raspbian stretch/main armhf Packages [11.7 MB]
下載:5 http://archive.raspberrypi.org/debian stretch/ui armhf Packages [44.6 kB]
下載:6 http://raspbian.raspberrypi.org/raspbian stretch/non-free armhf Packages [98.9 kB]
取得 12.0 MB 用了 20min 48s (9,640 B/s)                                        
正在讀取套件清單... 完成


3. 安裝五套件 : 

此五套件是支援 MQTT 協定的函式庫 : 

sudo apt-get install libc-ares-dev libwebsockets-dev libssl-dev xsltproc docbook-xsl 

pi@raspberrypi:~/Downloads/mosquitto-master $ sudo apt-get install libc-ares-dev libwebsockets-dev libssl-dev xsltproc docbook-xsl    
正在讀取套件清單... 完成
正在重建相依關係          
正在讀取狀態資料... 完成
下列的額外套件將被安裝:
  docbook-xml libev-dev libev4 libssl-doc libssl1.1 libuv1-dev libwebsockets8
  sgml-data
建議套件:
  docbook docbook-dsssl docbook-defguide dbtoepub docbook-xsl-doc-html
  | docbook-xsl-doc-pdf | docbook-xsl-doc-text | docbook-xsl-doc
  docbook-xsl-saxon fop libsaxon-java libxalan2-java libxslthl-java xalan
  perlsgml w3-recs opensp libxml2-utils
下列【新】套件將會被安裝:
  docbook-xml docbook-xsl libc-ares-dev libev-dev libev4 libssl-dev libssl-doc
  libuv1-dev libwebsockets-dev libwebsockets8 sgml-data xsltproc
下列套件將會被升級:
  libssl1.1
升級 1 個,新安裝 12 個,移除 0 個,有 335 個未被升級。
需要下載 4,105 kB/6,264 kB 的套件檔。
此操作完成之後,會多佔用 30.5 MB 的磁碟空間。
是否繼續進行 [Y/n]? [Y/n] Y
下載:1 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf libssl1.1 armhf 1.1.0l-1~deb9u2 [1,119 kB]
下載:2 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf libssl-dev armhf 1.1.0l-1~deb9u2 [1,388 kB]
下載:3 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf libssl-doc all 1.1.0l-1~deb9u2 [1,478 kB]
下載:4 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf xsltproc armhf 1.1.29-2.1+deb9u2 [120 kB]
取得 4,105 kB 用了 14s (284 kB/s)                                              
讀取改變紀錄(changelogs)... 完成
正在預先設定套件 ...
(讀取資料庫 ... 目前共安裝了 143563 個檔案和目錄。)
Preparing to unpack .../00-libssl1.1_1.1.0l-1~deb9u2_armhf.deb ...
Unpacking libssl1.1:armhf (1.1.0l-1~deb9u2) over (1.1.0j-1~deb9u1) ...
選取了原先未選的套件 sgml-data。
Preparing to unpack .../01-sgml-data_2.0.10_all.deb ...
Unpacking sgml-data (2.0.10) ...
選取了原先未選的套件 docbook-xml。
Preparing to unpack .../02-docbook-xml_4.5-8_all.deb ...
Unpacking docbook-xml (4.5-8) ...
選取了原先未選的套件 docbook-xsl。
Preparing to unpack .../03-docbook-xsl_1.79.1+dfsg-2_all.deb ...
Unpacking docbook-xsl (1.79.1+dfsg-2) ...
選取了原先未選的套件 libc-ares-dev:armhf。
Preparing to unpack .../04-libc-ares-dev_1.14.0-1~bpo9+1_armhf.deb ...
Unpacking libc-ares-dev:armhf (1.14.0-1~bpo9+1) ...
選取了原先未選的套件 libev4。
Preparing to unpack .../05-libev4_1%3a4.22-1_armhf.deb ...
Unpacking libev4 (1:4.22-1) ...
選取了原先未選的套件 libssl-dev:armhf。
Preparing to unpack .../06-libssl-dev_1.1.0l-1~deb9u2_armhf.deb ...
Unpacking libssl-dev:armhf (1.1.0l-1~deb9u2) ...
選取了原先未選的套件 libssl-doc。
Preparing to unpack .../07-libssl-doc_1.1.0l-1~deb9u2_all.deb ...
Unpacking libssl-doc (1.1.0l-1~deb9u2) ...
選取了原先未選的套件 libuv1-dev:armhf。
Preparing to unpack .../08-libuv1-dev_1.18.0-3~bpo9+1_armhf.deb ...
Unpacking libuv1-dev:armhf (1.18.0-3~bpo9+1) ...
選取了原先未選的套件 libwebsockets8:armhf。
Preparing to unpack .../09-libwebsockets8_2.0.3-2+b1~rpt1_armhf.deb ...
Unpacking libwebsockets8:armhf (2.0.3-2+b1~rpt1) ...
選取了原先未選的套件 libev-dev。
Preparing to unpack .../10-libev-dev_1%3a4.22-1_armhf.deb ...
Unpacking libev-dev (1:4.22-1) ...
選取了原先未選的套件 libwebsockets-dev:armhf。
Preparing to unpack .../11-libwebsockets-dev_2.0.3-2+b1~rpt1_armhf.deb ...
Unpacking libwebsockets-dev:armhf (2.0.3-2+b1~rpt1) ...
選取了原先未選的套件 xsltproc。
Preparing to unpack .../12-xsltproc_1.1.29-2.1+deb9u2_armhf.deb ...
Unpacking xsltproc (1.1.29-2.1+deb9u2) ...
設定 libev4 (1:4.22-1) ...
設定 docbook-xsl (1.79.1+dfsg-2) ...
設定 xsltproc (1.1.29-2.1+deb9u2) ...
Processing triggers for sgml-base (1.29) ...
Processing triggers for libc-bin (2.24-11+deb9u4) ...
設定 libssl1.1:armhf (1.1.0l-1~deb9u2) ...
設定 sgml-data (2.0.10) ...
Processing triggers for man-db (2.7.6.1-2) ...
設定 libc-ares-dev:armhf (1.14.0-1~bpo9+1) ...
設定 libssl-doc (1.1.0l-1~deb9u2) ...
設定 libuv1-dev:armhf (1.18.0-3~bpo9+1) ...
設定 libev-dev (1:4.22-1) ...
設定 libwebsockets8:armhf (2.0.3-2+b1~rpt1) ...
設定 libssl-dev:armhf (1.1.0l-1~deb9u2) ...
設定 libwebsockets-dev:armhf (2.0.3-2+b1~rpt1) ...
Processing triggers for sgml-base (1.29) ...
設定 docbook-xml (4.5-8) ...
Processing triggers for libc-bin (2.24-11+deb9u4) ...
Processing triggers for sgml-base (1.29) ...


4. 編譯原始碼與安裝套件 :

用 make 指令編譯原始碼 :

make -j4 

pi@raspberrypi:~/Downloads/mosquitto-master $ make -j4    
set -e; for d in lib apps client plugins src; do make -C ${d}; done
set -e; for d in man; do make -C ${d}; done
make[1]: Entering directory '/home/pi/Downloads/mosquitto-master/lib'
make[1]: Entering directory '/home/pi/Downloads/mosquitto-master/man'
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c mosquitto.c -o mosquitto.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c actions.c -o actions.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c callbacks.c -o callbacks.o
xsltproc --nonet libmosquitto.3.xml
xsltproc --nonet mosquitto-tls.7.xml
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c connect.c -o connect.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c handle_auth.c -o handle_auth.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c handle_connack.c -o handle_connack.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c handle_disconnect.c -o handle_disconnect.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c handle_ping.c -o handle_ping.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c handle_pubackcomp.c -o handle_pubackcomp.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c handle_publish.c -o handle_publish.o
xsltproc --nonet mosquitto.8.xml
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c handle_pubrec.c -o handle_pubrec.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c handle_pubrel.c -o handle_pubrel.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c handle_suback.c -o handle_suback.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c handle_unsuback.c -o handle_unsuback.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c helpers.c -o helpers.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c logging_mosq.c -o logging_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c loop.c -o loop.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c memory_mosq.c -o memory_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c messages_mosq.c -o messages_mosq.o
xsltproc --nonet mosquitto.conf.5.xml
xsltproc --nonet mosquitto_ctrl.1.xml
xsltproc --nonet mosquitto_ctrl_dynsec.1.xml
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c misc_mosq.c -o misc_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c net_mosq_ocsp.c -o net_mosq_ocsp.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c net_mosq.c -o net_mosq.o
xsltproc --nonet mosquitto_passwd.1.xml
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c options.c -o options.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c packet_datatypes.c -o packet_datatypes.o
xsltproc --nonet mosquitto_pub.1.xml
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c packet_mosq.c -o packet_mosq.o
xsltproc --nonet mosquitto_rr.1.xml
xsltproc --nonet mosquitto_sub.1.xml
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c property_mosq.c -o property_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c read_handle.c -o read_handle.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c send_connect.c -o send_connect.o
xsltproc --nonet mqtt.7.xml
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c send_disconnect.c -o send_disconnect.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c send_mosq.c -o send_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c send_publish.c -o send_publish.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c send_subscribe.c -o send_subscribe.o
make[1]: Leaving directory '/home/pi/Downloads/mosquitto-master/man'
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c send_unsubscribe.c -o send_unsubscribe.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c socks_mosq.c -o socks_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c srv_mosq.c -o srv_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c strings_mosq.c -o strings_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c thread_mosq.c -o thread_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c time_mosq.c -o time_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c tls_mosq.c -o tls_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c utf8_mosq.c -o utf8_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c util_mosq.c -o util_mosq.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c util_topic.c -o util_topic.o
cc  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps -Wall -ggdb -O2 -Wconversion -fPIC -c will_mosq.c -o will_mosq.o
cc -shared  -Wl,--version-script=linker.version -Wl,-soname,libmosquitto.so.1 mosquitto.o actions.o callbacks.o connect.o handle_auth.o handle_connack.o handle_disconnect.o handle_ping.o handle_pubackcomp.o handle_publish.o handle_pubrec.o handle_pubrel.o handle_suback.o handle_unsuback.o helpers.o logging_mosq.o loop.o memory_mosq.o messages_mosq.o misc_mosq.o net_mosq_ocsp.o net_mosq.o options.o packet_datatypes.o packet_mosq.o property_mosq.o read_handle.o send_connect.o send_disconnect.o send_mosq.o send_publish.o send_subscribe.o send_unsubscribe.o socks_mosq.o srv_mosq.o strings_mosq.o thread_mosq.o time_mosq.o tls_mosq.o utf8_mosq.o util_mosq.o util_topic.o will_mosq.o -o libmosquitto.so.1  -lrt -lssl -lcrypto -lpthread
make -C cpp
make[2]: Entering directory '/home/pi/Downloads/mosquitto-master/lib/cpp'
g++  -I. -I.. -I../include -I../../include -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_UNIX_SOCKETS -I../deps  -fPIC -c mosquittopp.cpp -o mosquittopp.o
g++ -shared  -Wl,-soname,libmosquittopp.so.1 mosquittopp.o -o libmosquittopp.so.1 ../libmosquitto.so.1 
make[2]: Leaving directory '/home/pi/Downloads/mosquitto-master/lib/cpp'
make[1]: Leaving directory '/home/pi/Downloads/mosquitto-master/lib'
make[1]: Entering directory '/home/pi/Downloads/mosquitto-master/apps'
set -e; for d in db_dump mosquitto_ctrl mosquitto_passwd; do make -C ${d}; done
make[2]: Entering directory '/home/pi/Downloads/mosquitto-master/apps/db_dump'
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c db_dump.c -o db_dump.o
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c print.c -o print.o
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c ../../lib/memory_mosq.c -o memory_mosq.o
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c ../../src/memory_public.c -o memory_public.o
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c ../../lib/packet_datatypes.c -o packet_datatypes.o
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c ../../lib/packet_mosq.c -o packet_mosq.o
db_dump.c: In function ‘dump__cfg_chunk_process’:
db_dump.c:133:98: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘unsigned int’ [-Wformat=]
 or: Incompatible database configuration (dbid size is %d bytes, expected %ld)",
                                                                            ^
db_dump.c: In function ‘dump__client_msg_chunk_process’:
db_dump.c:210:21: warning: conversion to ‘long unsigned int’ from ‘long int’ may change the sign of the result [-Wsign-conversion]
    cc->message_size += length;
                     ^~
db_dump.c:210:24: warning: conversion to ‘long int’ from ‘long unsigned int’ may change the sign of the result [-Wsign-conversion]
    cc->message_size += length;
                        ^~~~~~
db_dump.c:214:22: warning: conversion to ‘long unsigned int’ from ‘long int’ may change the sign of the result [-Wsign-conversion]
     cc->message_size += msc->length;
                      ^~
db_dump.c:214:25: warning: conversion to ‘long int’ from ‘long unsigned int’ may change the sign of the result [-Wsign-conversion]
     cc->message_size += msc->length;
                         ^~~
db_dump.c: In function ‘main’:
db_dump.c:466:19: warning: conversion to ‘long int’ from ‘uint32_t {aka unsigned int}’ may change the sign of the result [-Wsign-conversion]
      if(fseek(fd, length, SEEK_CUR) < 0){
                   ^~~~~~
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c ../../src/persist_read.c -o persist_read.o
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c ../../src/persist_read_v234.c -o persist_read_v234.o
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c ../../src/persist_read_v5.c -o persist_read_v5.o
../../src/persist_read.c: In function ‘persist__client_chunk_restore’:
../../src/persist_read.c:199:34: warning: conversion to ‘time_t {aka long int}’ from ‘int64_t {aka long long int}’ may alter its value [-Wconversion]
   context->session_expiry_time = chunk.F.session_expiry_time;
                                  ^~~~~
../../src/persist_read.c: In function ‘persist__restore’:
../../src/persist_read.c:527:18: warning: conversion to ‘long int’ from ‘uint32_t {aka unsigned int}’ may change the sign of the result [-Wsign-conversion]
      fseek(fptr, length, SEEK_CUR);
                  ^~~~~~
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c ../../lib/property_mosq.c -o property_mosq.o
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c ../../lib/send_disconnect.c -o send_disconnect.o
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c stubs.c -o stubs.o
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c ../../lib/time_mosq.c -o time_mosq.o
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c ../../src/topic_tok.c -o topic_tok.o
cc -Wall -ggdb -O2 -Wconversion -I../../include -I../../ -I../../lib -I../../src -I../../deps -DWITH_BROKER -DWITH_PERSISTENCE -c ../../lib/utf8_mosq.c -o utf8_mosq.o
cc db_dump.o print.o memory_mosq.o memory_public.o packet_datatypes.o packet_mosq.o persist_read.o persist_read_v234.o persist_read_v5.o property_mosq.o send_disconnect.o stubs.o time_mosq.o topic_tok.o utf8_mosq.o -o mosquitto_db_dump  
make[2]: Leaving directory '/home/pi/Downloads/mosquitto-master/apps/db_dump'
make[2]: Entering directory '/home/pi/Downloads/mosquitto-master/apps/mosquitto_ctrl'
cc -I../mosquitto_passwd  -I. -I../../ -I../../include -I../../src -I../../lib -DWITH_TLS -Wall -ggdb -O2 -Wconversion -DVERSION=\""2.0.5\"" -c mosquitto_ctrl.c -o mosquitto_ctrl.o
cc -I../mosquitto_passwd  -I. -I../../ -I../../include -I../../src -I../../lib -DWITH_TLS -Wall -ggdb -O2 -Wconversion -DVERSION=\""2.0.5\"" -c client.c -o client.o
cc -I../mosquitto_passwd  -I. -I../../ -I../../include -I../../src -I../../lib -DWITH_TLS -Wall -ggdb -O2 -Wconversion -DVERSION=\""2.0.5\"" -c dynsec.c -o dynsec.o
cc -I../mosquitto_passwd  -I. -I../../ -I../../include -I../../src -I../../lib -DWITH_TLS -Wall -ggdb -O2 -Wconversion -DVERSION=\""2.0.5\"" -c dynsec_client.c -o dynsec_client.o
dynsec_client.c:18:25: fatal error: cjson/cJSON.h: 沒有此一檔案或目錄
 #include <cjson/cJSON.h>
                         ^
compilation terminated.
Makefile:57: recipe for target 'dynsec_client.o' failed
make[2]: *** [dynsec_client.o] Error 1
make[2]: *** Waiting for unfinished jobs....
dynsec.c:20:25: fatal error: cjson/cJSON.h: 沒有此一檔案或目錄
 #include <cjson/cJSON.h>
                         ^
compilation terminated.
Makefile:54: recipe for target 'dynsec.o' failed
make[2]: *** [dynsec.o] Error 1
In file included from client.c:31:0:
mosquitto_ctrl.h:21:25: fatal error: cjson/cJSON.h: 沒有此一檔案或目錄
 #include <cjson/cJSON.h>
                         ^
compilation terminated.
Makefile:51: recipe for target 'client.o' failed
make[2]: *** [client.o] Error 1
In file included from mosquitto_ctrl.c:29:0:
mosquitto_ctrl.h:21:25: fatal error: cjson/cJSON.h: 沒有此一檔案或目錄
 #include <cjson/cJSON.h>
                         ^
compilation terminated.
Makefile:48: recipe for target 'mosquitto_ctrl.o' failed
make[2]: *** [mosquitto_ctrl.o] Error 1
make[2]: Leaving directory '/home/pi/Downloads/mosquitto-master/apps/mosquitto_ctrl'
Makefile:9: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/pi/Downloads/mosquitto-master/apps'
Makefile:66: recipe for target 'mosquitto' failed
make: *** [mosquitto] Error 2
pi@raspberrypi:~/Downloads/mosquitto-master $ 

編譯中出現 "Incompatible database configuration" 與 "fatal error: cjson/cJSON.h: 沒有此一檔案或目錄" 等錯誤訊息, 有空再查原因. 

如果 make -j4 編譯沒有錯誤, 後續還有兩個安裝指令 :

$ sudo make install  (安裝)
$ sudo ldconfig   


5. 建立 mosquitto 目錄 :

$ sudo mkdir /var/lib/mosquitto   


6. 編輯 mosquitto 設定檔 :

$ sudo nano /etc/mosquitto/mosquitto.conf

輸入如下內容 :

port 1883
listener 9001
protocol websockets
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/


7. 建立執行 mosquitto 的帳號 : 

一直按 Enter 即可, 密碼可任填 :

$ sudo adduser --shell /usr/sbin/nologin --no-create-home mosquitto 


8. 編輯服務檔 : 

$ sudo nano /etc/systemd/system/mosquitto.service 

輸入內容如下 : 

[Unit]
Description=Mosquitto MQTT Broker Deamon
ConditionPathExists=/etc/mosquitto/mosquitto.conf
After=network.target

[Service]
Type=forking
RemainAfterExit=no
StartLimitInterval=0
PIDFile=/var/run/mosquitto.pid
ExecStart=/bin/sh/ -c "/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d"
ExecReload=/bin/kill -HUB $MAINPID
Restart=on-failure
RestartSec=2

[Install]
WantedBy=multi-user.target

沒有留言:

張貼留言