在github上下载的源码:
wget https://github.com/eclipse/mosquitto/archive/v1.4.14.tar.gz
编译时,遇到了几个错误,在此小记,make时
read_handle_server.c:31:25: fatal error: uuid/uuid.h: No such file or directory
# include
^
compilation terminated.
make[1]: *** [read_handle_server.o] Error 1
make[1]: Leaving directory `/home/lxb/mosquitto/src'
make: *** [mosquitto] Error 2
解决方法:apt-get install uuid-dev
make[1]: Leaving directory `/home/lxb/mosquitto-1.4.14/src'
set -e; for d in man; do make -C ${d}; done
make[1]: Entering directory `/home/lxb/mosquitto-1.4.14/man'
xsltproc mosquitto.8.xml
make[1]: xsltproc: Command not found
make[1]: *** [mosquitto.8] Error 127
make[1]: Leaving directory `/home/lxb/mosquitto-1.4.14/man'
make: *** [docs] Error 2
这里说xsltproc命令找不到: apt-get install xsltproc-dev
make[1]: Entering directory `/home/lxb/mosquitto-1.4.14/man'
xsltproc mosquitto.8.xml
warning: failed to load external entity "/usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl"
compilation error: file manpage.xsl line 3 element import
xsl:import : unable to load /usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl
compilation error: file mosquitto.8.xml line 4 element refentry
xsltParseStylesheetProcess : document is not a stylesheet
make[1]: *** [mosquitto.8] Error 5
make[1]: Leaving directory `/home/lxb/mosquitto-1.4.14/man'
make: *** [docs] Error 2
然后就是mosquitt.8错误,看错误提示,根源还是找不到docbook.xsl
安装: apt-get install docbook-xsl
make:
install -d /usr/local/share/man/man8
install -m 644 mosquitto.8 /usr/local/share/man/man8/mosquitto.8
install -d /usr/local/share/man/man5
install -m 644 mosquitto.conf.5 /usr/local/share/man/man5/mosquitto.conf.5
install -d /usr/local/share/man/man1
install -m 644 mosquitto_passwd.1 /usr/local/share/man/man1/mosquitto_passwd.1
install -m 644 mosquitto_pub.1 /usr/local/share/man/man1/mosquitto_pub.1
install -m 644 mosquitto_sub.1 /usr/local/share/man/man1/mosquitto_sub.1
install -d /usr/local/share/man/man7
install -m 644 mqtt.7 /usr/local/share/man/man7/mqtt.7
install -m 644 mosquitto-tls.7 /usr/local/share/man/man7/mosquitto-tls.7
install -d /usr/local/share/man/man3
install -m 644 libmosquitto.3 /usr/local/share/man/man3/libmosquitto.3
make install :
install -d /usr/local/share/man/man8
install -m 644 mosquitto.8 /usr/local/share/man/man8/mosquitto.8
install -d /usr/local/share/man/man5
install -m 644 mosquitto.conf.5 /usr/local/share/man/man5/mosquitto.conf.5
install -d /usr/local/share/man/man1
install -m 644 mosquitto_passwd.1 /usr/local/share/man/man1/mosquitto_passwd.1
install -m 644 mosquitto_pub.1 /usr/local/share/man/man1/mosquitto_pub.1
install -m 644 mosquitto_sub.1 /usr/local/share/man/man1/mosquitto_sub.1
install -d /usr/local/share/man/man7
install -m 644 mqtt.7 /usr/local/share/man/man7/mqtt.7
install -m 644 mosquitto-tls.7 /usr/local/share/man/man7/mosquitto-tls.7
install -d /usr/local/share/man/man3
install -m 644 libmosquitto.3 /usr/local/share/man/man3/libmosquitto.3
终于通过了,启动mosquitto:mosquitto -v
1516959658: mosquitto version 1.4.14 (build date 2018-01-26 15:59:19+0800) starting
1516959658: Using default config.
1516959658: Opening ipv4 listen socket on port 1883.
1516959658: Opening ipv6 listen socket on port 1883.
1516959658: Error: Invalid user 'mosquitto'.
Error: Invalid user ‘mosquitto’,添加一个账户:sudo useradd mosquitto
mosquitto -v:
1516959895: mosquitto version 1.4.14 (build date 2018-01-26 15:59:19+0800) starting
1516959895: Using default config.
1516959895: Opening ipv4 listen socket on port 1883.
1516959895: Opening ipv6 listen socket on port 1883.
新开窗口分别进行订阅和发布:
订阅:mosquitto_sub -v -t test
test hello world(发布内容后显示)
发布: mosquitto_pub -t test -m “hello world”
另外还有一些错误:
【1】编译找不到openssl/ssl.h
【解决方法】——安装openssl
sudo apt-get install libssl-dev
【2】编译过程找不到ares.h
sudo apt-get install libc-ares-dev
【3】编译过程找不到uuid/uuid.h
sudo apt-get install uuid-dev
【4】使用过程中找不到libmosquitto.so.1
error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory
【解决方法】——修改libmosquitto.so位置
sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1
sudo ldconfig
【5】make: g++:命令未找到
【解决方法】
安装g++编译器
sudo apt-get install g++
接下来入手mqtt.fx(mqtt客户端),以及如何安卓上使用mqtt。
本次编译参考了大佬的博客:http://blog.csdn.net/xukai871105/article/details/39252653
在此表示感谢。