0

尝试编译示例之一时出现以下错误:

main.cpp:8:undefined reference to `mosqpp::lib_init()'
main.cpp:13: undefined reference to `mosqpp::mosquittopp::loop(int, int)'
main.cpp:15: undefined reference to `mosqpp::mosquittopp::reconnect()'
temperature_conversion.o: In function `mqtt_tempconv':
temperature_conversion.cpp:7: undefined reference to `mosqpp::mosquittopp::mosquittopp(char const*, bool)'
temperature_conversion.cpp:13: undefined reference to `mosqpp::mosquittopp::connect(char const*, int, int)'
temperature_conversion.cpp:7: undefined reference to `mosqpp::mosquittopp::~mosquittopp()'
temperature_conversion.o: In function `mqtt_tempconv::on_connect(int)':
temperature_conversion.cpp:21: undefined reference to `mosqpp::mosquittopp::subscribe(int*, char const*, int)'
temperature_conversion.o: In function `mqtt_tempconv::on_message(mosquitto_message const*)':
temperature_conversion.cpp:37: undefined reference to `mosqpp::mosquittopp::publish(int*, char const*, int, void const*, int, bool)'

请帮忙

4

2 回答 2

2

您的问题没有提供太多细节 - 您应该描述您是如何处理它的以及问题是什么。

话虽如此,看起来你还没有链接到图书馆。

如果你是这样编译的:

g++ main.o temperature_conversion.o -o temperature_conversion 

然后你需要链接到图书馆:

g++ main.o temperature_conversion.o -o temperature_conversion -lmosquittopp

我假设它已经安装了。

于 2014-10-13T11:59:23.347 回答
0

locate libmosquittopp.so可以帮助您了解作为 -L 参数提供给 g++ 的目录。

g++ main.o temperature_conversion.o -o temperature_conversion -lmosquittopp \
    -L$(locate libmosquitto.so | tail -n 1 | xargs -n1 dirname)
于 2018-05-09T14:48:45.710 回答