我正在尝试编译 libmosquitto 网站(底部)上提供的代码示例:http: //mosquitto.org/man/libmosquitto-3.html
我正在使用 Ubuntu 12.04,并且我已经安装了 libmosquitto1 和 libmosquitto1-dev 软件包。在安装它们之前,我添加了 mosquitto 存储库:
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
我正在尝试编译示例如下:
gcc -lmosquitto mosquito.c -o mosquito
但我收到以下错误:
/tmp/cc6eU8kw.o: In function `my_connect_callback':
mosquito.c:(.text+0xf8): undefined reference to `mosquitto_subscribe'
/tmp/cc6eU8kw.o: In function `main':
mosquito.c:(.text+0x298): undefined reference to `mosquitto_lib_init'
mosquito.c:(.text+0x2b4): undefined reference to `mosquitto_new'
mosquito.c:(.text+0x310): undefined reference to `mosquitto_log_callback_set'
mosquito.c:(.text+0x324): undefined reference to `mosquitto_connect_callback_set'
mosquito.c:(.text+0x338): undefined reference to `mosquitto_message_callback_set'
mosquito.c:(.text+0x34c): undefined reference to `mosquitto_subscribe_callback_set'
mosquito.c:(.text+0x364): undefined reference to `mosquitto_connect'
mosquito.c:(.text+0x3b4): undefined reference to `mosquitto_loop'
mosquito.c:(.text+0x3c8): undefined reference to `mosquitto_destroy'
mosquito.c:(.text+0x3d0): undefined reference to `mosquitto_lib_cleanup'
collect2: ld returned 1 exit status
有人可以给我一些关于如何编译这个简单示例的提示吗?谢谢