Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22248

Linking mosquitto library to hello.c program on Linux

$
0
0

I am trying to compile the mosquitto library with my custom c program. So WHat I have done is wrote a hello.c file, git cloned the latest mosquitto library from the below repository:

https://github.com/eclipse/mosquitto.git

and compiled it with the make command as below:

make

I had to remove the doc target as it was asking for some dependancy library. I don't have admin rights on this machine, hence don't want to be blocked by any dependancy lib. After the compilation what I have is the below:

src/mosquitto ./lib/libmosquitto.so.1  

The I copied the libmosquitto.so.1 shared lib into a local folder called ~/hello/:

~/hello$ cp ~/mosquitto/lib/libmosquitto.so.1 .

then wrote a hello.c inside ~/hello/ which is as below:

#include <stdio.h>int main(){    printf("Hello World\n");    return 0;}

I can compile the hello.c and run it as below:

gcc -o hello hello.c./helloHello World

But if I try to link the binary with the mosquitto library I get an error like the below:

gcc -o hello hello.c -lmosquitto/usr/bin/ld: cannot find -lmosquittocollect2: error: ld returned 1 exit status

The libmosquitto.so.1 lives in the same folder as the hello.c. I don't want to install the mosquitto library, rather would like to keep in a local folder and be able to link it. I have also tried the below with the hope that the -L. would point the linker to the present directory for the shared lib file but still get the same error:

 gcc -o hello hello.c -L. -lmosquitto/usr/bin/ld: cannot find -lmosquittocollect2: error: ld returned 1 exit status

My ultimate objective is to cross compile the library for an arm target. So really need to understand how the linking of the shared library is failing so that I can use the same experience while cross compiling and link for the target. At the moment I am doing this on a x86 platform.Can anyone please help?


Viewing all articles
Browse latest Browse all 22248

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>