【发布时间】:2017-04-15 15:23:07
【问题描述】:
我正在尝试将MQTT-C-Client-Library 包含在一个简单的 C++ 项目中。
我已经成功地包含了这个头文件#include "MQTTClient.h"。在 linux 终端中编译它会打印这个错误:
[xy@localhost mosquittoProject]$ sudo g++ *.cpp -o MQTTTest
/tmp/ccHn3s6m.o: In function `main':
mosquitto_test.cpp:(.text+0x11e): undefined reference to `MQTTClient_create'
mosquitto_test.cpp:(.text+0x13f): undefined reference to `MQTTClient_connect'
collect2: error: ld returned 1 exit status
经过一番谷歌搜索后,我发现我需要链接库:Example MQTT Client Code not working C
基于这个问题和答案,我尝试像这样再次编译它:
sudo g++ -L/home/xy/Desktop/paho.mqtt.c/build/output/ *.cpp -l paho-mqtt3c -o MQTTTest
编译正常,但运行时仍然出现错误。 控制台命令和输出:
[xy@localhost mosquittoProject]$ sudo g++ -L/home/xy/Desktop/paho.mqtt.c/build/output/ *.cpp -l paho-mqtt3c -o MQTTTest
[xy@localhost mosquittoProject]$ ./MQTTTest
./MQTTTest: error while loading shared libraries: libpaho-mqtt3c.so.1: cannot open shared object file: No such file or directory
我在这篇文章中用 xy 替换了实际用户名。
我在这里做错了什么?
【问题讨论】: