mosquitto 编译

参考

https://goochgooch.wordpress.com/2014/08/01/building-mosquitto-1-4/
https://github.com/eclipse/mosquitto
https://github.com/bapowell/bapowell.github.io/wiki/Mosquitto-Build-Notes-(Linux)

下载源码

git clone git@github.com:eclipse/mosquitto.git

安装依赖

  1. sudo apt-get install uuid-dev xsltproc docbook-xsl libssl-dev
  2. 提示 ares.h 找不到, 安装 c-ares

wget http://c-ares.haxx.se/download/c-ares-1.10.0.tar.gz
tar xvf c-ares-1.10.0.tar.gz
cd c-ares-1.10.0/
./configure
sudo make install

修改 config.mk

c-ares (libc-ares-dev on Debian based systems) - disable with make WITH_SRV=no
libuuid (uuid-dev) - disable with make WITH_UUID=no
libwebsockets (libwebsockets-dev) - enable with make WITH_WEBSOCKETS=yes
openssl (libssl-dev on Debian based systems) - disable with make WITH_TLS=no

  1. 可以修改编译选项,跳过生成doc,则注释掉 WITH_DOCS
#WITH_DOCS:=yes

编译

make binary

测试

  1. 服务端 mosquitto
    在源码根目录 ./src/mosquitto

  2. 客户端 mosquito_sub,mosquito_pub
    在源码根目录 ./client/mosquitto

》mosquitto_pub: error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory

/sbin/ldconfig as root/sudo

  1. 测试
>./src/mosquitto &
1500302756: mosquitto version 1.4.13 (build date 2017-07-17 22:19:54+0800) starting
1500302756: Using default config.
1500302756: Opening ipv4 listen socket on port 1883.
1500302756: Opening ipv6 listen socket on port 1883.
>mosquitto_sub -t "topic" &
1500302862: New connection from 127.0.0.1 on port 1883.
1500302862: New client connected from 127.0.0.1 as mosq_sub_21276_ra1z (c1, k60).
>mosquitto_pub -t "topic" -m "hello"
1500302977: New connection from 127.0.0.1 on port 1883.
1500302977: New client connected from 127.0.0.1 as mosq_pub_21278_ra1z (c1, k60).
1500302977: Client mosq_pub_21278_ra1z disconnected.
hello

安装到系统

make install

环境

bash on ubuntu on windows

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容