如何使用libmosquitto进行编译 [英] How to compile using libmosquitto

查看:804
本文介绍了如何使用libmosquitto进行编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译libmosquitto网站(底部)上提供的代码示例: http://mosquitto.org/man/libmosquitto-3.html

Iam trying to compile the code example available on the libmosquitto website (at the bottom): http://mosquitto.org/man/libmosquitto-3.html

我使用Ubuntu 12.04安装了libmosquitto1和libmosquitto1-dev软件包.在安装它们之前,我添加了mosquitto存储库:

Iam using Ubuntu 12.04 and I've installed libmosquitto1 and libmosquitto1-dev packages. Before installing them I added the mosquitto repository:

sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update

我正在尝试按以下方式编译示例:

Iam trying to compile the example as follows:

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

有人可以给我一些有关如何编译此简单示例的提示吗? 谢谢

Can someone give me some tips on how to compile this simple example? Thanks

推荐答案

您必须将-lmosquitto放在末尾(源文件之后).

You have to put the -lmosquitto at the end (after the source files).

gcc mosquito.c -lmosquitto -o mosquito
# or
gcc mosquito.c -o mosquito -lmosquitto
# or
gcc -o mosquito mosquito.c -lmosquitto

或更佳:

gcc -Wall -Wextra -pedantic -o mosquito mosquito.c -lmosquitto

这篇关于如何使用libmosquitto进行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆