首页 > 解决方案 > gcc -lmosquitto 时的链接错误

问题描述

我在我的橙色 pi 上下载并安装 mosquitto-1.5.8.tar.gz,然后编写一个程序来测试它:

#include <stdio.h>
#include <mosquitto.h>
int main(void){

    mosquitto_lib_init();

    printf("OK\n");

    mosquitto_lib_cleanup();

}

但是当我尝试编译它时,我得到了这个错误:

`root@orangepilite:/# gcc test.c -o test
/tmp/ccMUyHdP.o: In function `main':
test.c:(.text+0x4): undefined reference to 'mosquitto_lib_init'
test.c:(.text+0x14): undefined reference to 'mosquitto_lib_cleanup'
collect2: error: ld returned 1 exit status`

然后我试试这个:

root@orangepilite:/# gcc test.c -o test -lmosquitto
/usr/bin/ld: warning: librt.so.0, needed by /usr/lib/gcc/arm-linux- 
gnueabihf/5/../../../arm-linux-gnueabihf/libmosquitto.so, not found (try 
using -rpath or -rpath-link)
/usr/bin/ld: warning: libc.so.0, needed by /usr/lib/gcc/arm-linux- 
gnueabihf/5/../../../arm-linux-gnueabihf/libmosquitto.so, not found (try 
using -rpath or -rpath-link)
/usr/lib/gcc/arm-linux-gnueabihf/5/../../../arm-linux- 
gnueabihf/libmosquitto.so: undefined reference to `fcntl64'
collect2: error: ld returned 1 exit status

我是 mosquitto 和 linux 的新手,我真的不知道是什么问题,希望有人能帮助我。

这是 API 链接http://mosquitto.org/api/files/mosquitto-h.html,在这里下载mosquitto.org/download

标签: clinuxgcclinker-errorsmosquitto

解决方案


推荐阅读