makefilemariadb

How can i insert a link to MariaDB into an existing Makefile


I have an existing & working Makefile and want add MariaDB (mysql.h). My problem is:

gcc -o example MariaDBTest.c $(mariadb_config --include --libs)

works fine. But how/where can i insert it to my Makefile:

CC = gcc -Wno-unknown-pragmas -Wall -Wextra
PKGCONFIG = $(shell which pkg-config)
CFLAGS = $(shell $(PKGCONFIG) --cflags gtk+-3.0 --libs) -lbcm2835 -rdynamic -lm
DEPS = LinkedList.h StructDefinitions.h
%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)
OBJ = reTerminal.c \
    Sensors/CpuGpuTemp.c Sensors/ReadSensores.c Sensors/TempSensorExtern.c \
    Connectivity/ClientSide.c Connectivity/ServerSide.c \
    GUI/MainApp.c GUI/MainAppWindow.c GUI/BasicFrame.c GUI/SimpleFrame.c \
    Data/MariaDBTest.c
Main: $(OBJ)
    $(CC) -o $@ $^ $(CFLAGS)

System: Linux/RasPi5


Solution

  • This looks wrong to me:

    $(shell $(PKGCONFIG) --cflags gtk+-3.0 --libs)
    

    Are you sure you don't get warnings from the compiler about unused linker options or something?

    You should separate your compilation flags (CFLAGS) from your linker library flags (by convention, LDLIBS). Write it like this:

    CFLAGS := $(shell $(PKGCONFIG) gtk+-3.0 --cflags) $(shell mariadb_config --include)
    LDLIBS := $(shell $(PKGCONFIG) gtk+-3.0 --libs) $(shell mariadb_config --libs) -lbcm2835 -rdynamic -lm
       ...
    %.o: %.c $(DEPS)
            $(CC) $(CFLAGS) -c -o $@ $<
       ...
    Main: $(OBJ)
            $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS)