0

I download and install mosquitto-1.5.8.tar.gz on my orange pi, and I write a program to test it:

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

    mosquitto_lib_init();

    printf("OK\n");

    mosquitto_lib_cleanup();

}

But when I try to compile it, I get this error:

`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`

Then I try this:

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

I'm new to mosquitto and linux, I really don't know what's the problem, wish someone could help me with it.

Here's the API link http://mosquitto.org/api/files/mosquitto-h.html, download here mosquitto.org/download

jww
  • 97,681
  • 90
  • 411
  • 885
  • To improve your question, could you share a link to the API docs for the mosquitto library? Might help someone be able to answer more quickly and catch any differences between them and what you have written. – Scotty Waggoner Mar 19 '19 at 05:53
  • 1
    Specifying `-lrt` for `librt.so` is not that uncommon. You only need to `gcc test.c -o test -lmosquitto -lrt`. However, the missing `libc.so` is unusual. Where did GCC come from? – jww Mar 19 '19 at 06:26
  • *"I download and install mosquitto-1.5.8.tar.gz..."* - I guess that means you `./configure && make && sudo make install`. Mosquitto should be located in `/usr/local` unless you did something different. As such, you should add `-I/usr/local/include` and `-L/usr/local/lib` to you compile/link command. Also see [How to compile example program using libmosquitto](https://stackoverflow.com/q/26334502/608639) and [How to compile using libmosquitto](https://stackoverflow.com/q/19707329/608639) – jww Mar 19 '19 at 06:32
  • 1
    I know the reason, the toolchain I'm using is built by glibc. But the mosquitto is uClibc, my bad. – Kevin Zeng Mar 19 '19 at 06:35
  • Thank you for mention librt.so, otherwise I would never noitce it. – Kevin Zeng Mar 19 '19 at 06:39
  • 2
    1. But if you build mosquitto from sources using the same compiler and same environment, then it would be build by glibc. 2. If you have found the solution, write an answer to your post and feel free to accept it. – KamilCuk Mar 19 '19 at 07:00

0 Answers0