当我尝试编译其中一个示例时,我收到以下错误:
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)'
请帮忙
答案 0 :(得分:2)
您的问题没有提供太多详细信息 - 您应该描述 你是如何做到这一点以及问题所在。
话虽如此,看起来你没有链接到图书馆。
如果您正在编译:
g++ main.o temperature_conversion.o -o temperature_conversion
然后你需要链接到库:
g++ main.o temperature_conversion.o -o temperature_conversion -lmosquittopp
我假设它已经安装。
答案 1 :(得分:0)
locate libmosquittopp.so
可以帮助您理解g ++ as -L参数的目录。
g++ main.o temperature_conversion.o -o temperature_conversion -lmosquittopp \
-L$(locate libmosquitto.so | tail -n 1 | xargs -n1 dirname)