首页 > 解决方案 > 在树莓派上安装 mqtt 客户端库

问题描述

我一直在尝试在 raspbian buster 上编译 Paho MQTT 客户端库。克隆了github源码:

git clone https://github.com/eclipse/paho.mqtt.c.git

根据 README 文件,我运行了 make(除了 1 个警告“rc1 not used”之外,还可以),然后 sudo make install 会愉快地将各种 MQTTxx.h 和 MQTTxx.c 文件复制到 /usr/include 目录中。

但是,尝试编译 Paho 演示程序会导致:

richard@grigio:[~]: gcc mqtest.c
/tmp/ccvjYcVw.o: In function `main':
mqtest.c:(.text+0x68): undefined reference to `MQTTClient_create'
mqtest.c:(.text+0x8c): undefined reference to `MQTTClient_connect'
mqtest.c:(.text+0xe4): undefined reference to `MQTTClient_publishMessage'
mqtest.c:(.text+0x114): undefined reference to `MQTTClient_waitForCompletion'
mqtest.c:(.text+0x138): undefined reference to `MQTTClient_disconnect'
mqtest.c:(.text+0x144): undefined reference to `MQTTClient_destroy'
collect2: error: ld returned 1 exit status

所以我想我需要链接图书馆:

richard@grigio:[~]: gcc mqtest.c -lMQTTClient
/usr/bin/ld: cannot find -lMQTTClient
collect2: error: ld returned 1 exit status

MQTTClient.h 和 MQTTClient.c 存在于 /usr/include 中,请问我做错了什么?

标签: c

解决方案


推荐阅读