Linux(CentOS)安装mosquitto client emqxmosquitto clientcentosg++.so
程序员文章站
2022-04-04 16:50:02
...
1> 切换到目录,注意不是src下
cd /data/backup/mosquitto-1.4.5
2> 执行编译操作
# make
set -e; for d in lib client src; do make -C ${d}; done
make[1]: Entering directory `/data/backup/mosquitto-1.4.5/lib'
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_SRV -c mosquitto.c -o mosquitto.o
In file included from mosquitto.c:33:
./mosquitto_internal.h:40:20: error: ares.h: No such file or directory
In file included from mosquitto.c:33:
./mosquitto_internal.h:249: error: expected specifier-qualifier-list before ‘ares_channel’
mosquitto.c: In function ‘mosquitto_loop’:
mosquitto.c:880: error: ‘struct mosquitto’ has no member named ‘achan’
mosquitto.c:883: warning: implicit declaration of function ‘ares_fds’
mosquitto.c:883: error: ‘struct mosquitto’ has no member named ‘achan’
mosquitto.c:982: error: ‘struct mosquitto’ has no member named ‘achan’
mosquitto.c:983: warning: implicit declaration of function ‘ares_process’
mosquitto.c:983: error: ‘struct mosquitto’ has no member named ‘achan’
make[1]: *** [mosquitto.o] Error 1
make[1]: Leaving directory `/data/backup/mosquitto-1.4.5/lib'
make: *** [mosquitto] Error 2
3> 修改编译配置文件【config.mk】
# vim ./config.mk
把WITH_SRV:=yes 改成WITH_SRV:=no 就可以编译了
4> g++: Command not found => 两步yum安装
=>yum -y install gcc automake autoconf libtool make
=>yum install gcc gcc-c++
# make
set -e; for d in lib client src; do make -C ${d}; done
make[1]: Entering directory `/data/backup/mosquitto-1.4.5/lib'
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c mosquitto.c -o mosquitto.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c logging_mosq.c -o logging_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c memory_mosq.c -o memory_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c messages_mosq.c -o messages_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c net_mosq.c -o net_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c read_handle.c -o read_handle.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c read_handle_client.c -o read_handle_client.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c read_handle_shared.c -o read_handle_shared.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c send_mosq.c -o send_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c send_client_mosq.c -o send_client_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c socks_mosq.c -o socks_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c srv_mosq.c -o srv_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c thread_mosq.c -o thread_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c time_mosq.c -o time_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c tls_mosq.c -o tls_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c util_mosq.c -o util_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c will_mosq.c -o will_mosq.o
cc -shared -Wl,--version-script=linker.version -Wl,-soname,libmosquitto.so.1 mosquitto.o logging_mosq.o memory_mosq.o messages_mosq.o net_mosq.o read_handle.o read_handle_client.o read_handle_shared.o send_mosq.o send_client_mosq.o socks_mosq.o srv_mosq.o thread_mosq.o time_mosq.o tls_mosq.o util_mosq.o will_mosq.o -o libmosquitto.so.1 -lrt -lssl -lcrypto -lpthread
ar cr libmosquitto.a mosquitto.o logging_mosq.o memory_mosq.o messages_mosq.o net_mosq.o read_handle.o read_handle_client.o read_handle_shared.o send_mosq.o send_client_mosq.o socks_mosq.o srv_mosq.o thread_mosq.o time_mosq.o tls_mosq.o util_mosq.o will_mosq.o
make -C cpp
make[2]: Entering directory `/data/backup/mosquitto-1.4.5/lib/cpp'
g++ -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -c mosquittopp.cpp -o mosquittopp.o
make[2]: g++: Command not found
make[2]: *** [mosquittopp.o] Error 127
make[2]: Leaving directory `/data/backup/mosquitto-1.4.5/lib/cpp'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/data/backup/mosquitto-1.4.5/lib'
make: *** [mosquitto] Error 2
#
5> # /usr/local/bin/mosquitto_sub -h emqx.io -t $SYS/# -q 2 -d
./mosquitto_sub: error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory
=>修改libmosquitto.so.1位置
# 创建链接
sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1
# 更新动态链接库
sudo ldconfig
6> 成功订阅
# /usr/local/bin/mosquitto_sub -h localhost -t $SYS/# -u can_do -P passw0rd -q 2 -d
Client mosqsub/23035-test sending CONNECT
Client mosqsub/23035-test received CONNACK
Client mosqsub/23035-test sending SUBSCRIBE (Mid: 1, Topic: /#, QoS: 2)
Client mosqsub/23035-test received SUBACK
Subscribed (mid: 1): 2
cd /data/backup/mosquitto-1.4.5
2> 执行编译操作
# make
set -e; for d in lib client src; do make -C ${d}; done
make[1]: Entering directory `/data/backup/mosquitto-1.4.5/lib'
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_SRV -c mosquitto.c -o mosquitto.o
In file included from mosquitto.c:33:
./mosquitto_internal.h:40:20: error: ares.h: No such file or directory
In file included from mosquitto.c:33:
./mosquitto_internal.h:249: error: expected specifier-qualifier-list before ‘ares_channel’
mosquitto.c: In function ‘mosquitto_loop’:
mosquitto.c:880: error: ‘struct mosquitto’ has no member named ‘achan’
mosquitto.c:883: warning: implicit declaration of function ‘ares_fds’
mosquitto.c:883: error: ‘struct mosquitto’ has no member named ‘achan’
mosquitto.c:982: error: ‘struct mosquitto’ has no member named ‘achan’
mosquitto.c:983: warning: implicit declaration of function ‘ares_process’
mosquitto.c:983: error: ‘struct mosquitto’ has no member named ‘achan’
make[1]: *** [mosquitto.o] Error 1
make[1]: Leaving directory `/data/backup/mosquitto-1.4.5/lib'
make: *** [mosquitto] Error 2
3> 修改编译配置文件【config.mk】
# vim ./config.mk
把WITH_SRV:=yes 改成WITH_SRV:=no 就可以编译了
4> g++: Command not found => 两步yum安装
=>yum -y install gcc automake autoconf libtool make
=>yum install gcc gcc-c++
# make
set -e; for d in lib client src; do make -C ${d}; done
make[1]: Entering directory `/data/backup/mosquitto-1.4.5/lib'
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c mosquitto.c -o mosquitto.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c logging_mosq.c -o logging_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c memory_mosq.c -o memory_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c messages_mosq.c -o messages_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c net_mosq.c -o net_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c read_handle.c -o read_handle.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c read_handle_client.c -o read_handle_client.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c read_handle_shared.c -o read_handle_shared.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c send_mosq.c -o send_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c send_client_mosq.c -o send_client_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c socks_mosq.c -o socks_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c srv_mosq.c -o srv_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c thread_mosq.c -o thread_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c time_mosq.c -o time_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c tls_mosq.c -o tls_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c util_mosq.c -o util_mosq.o
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -c will_mosq.c -o will_mosq.o
cc -shared -Wl,--version-script=linker.version -Wl,-soname,libmosquitto.so.1 mosquitto.o logging_mosq.o memory_mosq.o messages_mosq.o net_mosq.o read_handle.o read_handle_client.o read_handle_shared.o send_mosq.o send_client_mosq.o socks_mosq.o srv_mosq.o thread_mosq.o time_mosq.o tls_mosq.o util_mosq.o will_mosq.o -o libmosquitto.so.1 -lrt -lssl -lcrypto -lpthread
ar cr libmosquitto.a mosquitto.o logging_mosq.o memory_mosq.o messages_mosq.o net_mosq.o read_handle.o read_handle_client.o read_handle_shared.o send_mosq.o send_client_mosq.o socks_mosq.o srv_mosq.o thread_mosq.o time_mosq.o tls_mosq.o util_mosq.o will_mosq.o
make -C cpp
make[2]: Entering directory `/data/backup/mosquitto-1.4.5/lib/cpp'
g++ -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -c mosquittopp.cpp -o mosquittopp.o
make[2]: g++: Command not found
make[2]: *** [mosquittopp.o] Error 127
make[2]: Leaving directory `/data/backup/mosquitto-1.4.5/lib/cpp'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/data/backup/mosquitto-1.4.5/lib'
make: *** [mosquitto] Error 2
#
5> # /usr/local/bin/mosquitto_sub -h emqx.io -t $SYS/# -q 2 -d
./mosquitto_sub: error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory
=>修改libmosquitto.so.1位置
# 创建链接
sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1
# 更新动态链接库
sudo ldconfig
6> 成功订阅
# /usr/local/bin/mosquitto_sub -h localhost -t $SYS/# -u can_do -P passw0rd -q 2 -d
Client mosqsub/23035-test sending CONNECT
Client mosqsub/23035-test received CONNACK
Client mosqsub/23035-test sending SUBSCRIBE (Mid: 1, Topic: /#, QoS: 2)
Client mosqsub/23035-test received SUBACK
Subscribed (mid: 1): 2
上一篇: 修改php.ini文件不生效怎么办?
下一篇: 小程序体验版如何变正式版