Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Makefile cant find libraries

I’m trying to write my own makefile for a paho.mqtt project on a Raspberry Pi 4.

I’ve downloaded & tested the paho.mqtt install and its all working as expected.

So I’m now testing some C code but I just cant figure out the makefile (I’m new to this), my file so far,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

NAME = mqtt_test
OBJ = $(NAME).o
LIBS = -libpaho-mqtt3c -libpaho-mqtt3cs
CFLAGS = -Wall -I/usr/local/include -L/usr/local/lib
CC = gcc
EXTENSION = .c

all: $(NAME)

%.o: %$(EXTENSION) $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)

$(NAME): $(OBJ)
    $(CC) -o $@ $^ $(CFLAGS) $(LIBS)

.PHONY: clean

clean:
    @rm -f *.o *~ core $(NAME)

This returns,

gcc -o mqtt_test mqtt_test.o -Wall -I/usr/local/include  -L/usr/local/lib -libpaho-mqtt3c -libpaho-mqtt3cs
/usr/bin/ld: cannot find -libpaho-mqtt3c
/usr/bin/ld: cannot find -libpaho-mqtt3cs
collect2: error: ld returned 1 exit status
make: *** [makefile:14: mqtt_test] Error 1

I’ve checked & the includes and libraries are in the directories I put after the-I and -L flags.

When I look in /usr/bin there is no ld but there are paho files prefixed with paho_ but no library files.

What am I missing?

>Solution :

You don’t use -libpaho-mqtt3c (etc.)

The option is -l so when you write -libpaho-mqtt3c the linker is looking for libraries named ibpaho-mqtt3c which of course do not exist: that would be either libibpaho-mqtt3c.a or libibpaho-mqtt3c.so.

You want to use -lpaho-mqtt3c: remove the lib at the front and the extension .a or .so, and add in the option -l.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading