October 22, 2024
Chicago 12, Melborne City, USA
C#

I am unable to include mosquitto.h to c program on mac


I am trying to use mosquitto.h in my c program.

I installed mosquitto with homebrew:

brew install mosquitto

but when I run:

gcc mqtt_subscriber_01.c -o mqtt_subscriber_01 -lmosquitto

I get:

mqtt_subscriber_01.c:4:10: fatal error: 'mosquitto.h' file not found
#include <mosquitto.h>
         ^~~~~~~~~~~~~
1 error generated.

I create this Makefile:

CC = gcc

LIBS = -lmosquitto

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

make: mqtt_subscriber_01.c
    $(CC) -Wall -o test $^ $(LIBS)

.PHONY: clean

Output of make is:

gcc -Wall -o test mqtt_subscriber_01.c -lmosquitto
mqtt_subscriber_01.c:4:10: fatal error: 'mosquitto.h' file not found
#include <mosquitto.h>
         ^~~~~~~~~~~~~
1 error generated.
make: *** [make] Error 1

I am a beginner to c and especially to installing libraries.

My machine is mac m1 running ventura 13.3.1 (a) .

Any help is much appreciated.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video