1、下载mosquitto-2.0.14源码:

wget https://github.com/eclipse/mosquitto/archive/refs/tags/v2.0.14.tar.gz

2、解压后进入目录执行编译sudo make报错,提示无法引用EVP_idea_cbc@OPENSSL_1_1_0

//usr/local/ssl/lib/libssl.so.1.1: undefined reference to `EVP_idea_cbc@OPENSSL_1_1_0'
collect2: error: ld returned 1 exit status
Makefile:45: recipe for target 'mosquitto_ctrl' failed
make[2]: *** [mosquitto_ctrl] Error 1
make[2]: Leaving directory '/home/gbinb/Downloads/mosquitto-2.0.14/apps/mosquitto_ctrl'
Makefile:9: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/gbinb/Downloads/mosquitto-2.0.14/apps'
Makefile:66: recipe for target 'mosquitto' failed
make: *** [mosquitto] Error 2

在安装mosquitto之前,我卸载了机器上旧的openssl,源码编译安装了 openssl-OpenSSL_1_1_1m,目前看仍然是引用的旧的openssl版本;但是/usr/local/ssl/lib/libssl.so.1.1也的确是引用的新版本的库,根据/home/gbinb/Downloads/mosquitto-2.0.14/apps/mosquitto_ctrl这个提示找到了源码下的Makefile文件,找了第9行报错的地方:

include ../../config.mk

.PHONY: all install uninstall clean reallyclean

ifeq ($(WITH_SHARED_LIBRARIES),yes)
LIBMOSQ:=../../lib/libmosquitto.so.${SOVERSION}
else
ifeq ($(WITH_THREADING),yes)
LIBMOSQ:=../../lib/libmosquitto.a -lpthread -lssl -lcrypto  #这里依赖了ssl和crypto,都是openssl中的动态链接库
else
LIBMOSQ:=../../lib/libmosquitto.a
endif
endif

通过搜索ssl,发现在/usr/lib/x86_64-linux-gnu目录下有一些ssl的动态库:

gbinb@ubuntu:/usr/lib/x86_64-linux-gnu$ ls|grep libssl
libssl3.so
libssl.a
libssl.so
libssl.so.1.0.0
libssl.so.1.1

于是将这些库删除,并把我自己安装在 /usr/local/ssl/lib下的库复制到/usr/lib/x86_64-linux-gnu目录下:

gbinb@ubuntu:/usr/local/ssl/lib$ ls
engines-1.1  libcrypto.so      libssl.a   libssl.so.1.1
libcrypto.a  libcrypto.so.1.1  libssl.so  pkgconfig

然后再编译,openssl相关的错误没有了,但出现另外一个错误:

make[1]: Leaving directory '/home/gbinb/Downloads/mosquitto-2.0.14/src'
set -e; for d in man; do make -C ${d}; done
make[1]: Entering directory '/home/gbinb/Downloads/mosquitto-2.0.14/man'
xsltproc --nonet libmosquitto.3.xml
make[1]: xsltproc: Command not found
Makefile:90: recipe for target 'libmosquitto.3' failed
make[1]: *** [libmosquitto.3] Error 127
make[1]: Leaving directory '/home/gbinb/Downloads/mosquitto-2.0.14/man'
Makefile:57: recipe for target 'docs' failed
make: *** [docs] Error 2

看了一个是缺少xsltproc依赖,这里要安装docbook-xsl xsltproc,只安装xsltproc仍然编译不过去,也是折腾了半天,找文档中的Readme.md发现的,也可以在编译时加WITH_DOCS=no参数忽略:

xsltproc (xsltproc and docbook-xsl on Debian based systems) - only needed when building from git sources - disable with `make WITH_DOCS=no`

最后清理编译缓存,重新再编译通过,安装成功!!!

发表评论