In my project i have directory structure /libs
and /src
. I want to create makefile
where main
has dependency in /libs
. ie. header file is in the /libs
. I have used the following
#Compiler to use
CC=gcc
#Compiler flags to use
CFLAGS=-c -Wall
BUILD = ./build
SRC = ./src
LIBS = ./libs
SOURCES = $(SRC)/main.c $(SRC)/SmallComponent1.c $(SRC)/SmallComponent2.c $(LIBS)/ExtLib.c
OBJECTS = $(SOURCES: .c=.o)
EXECUTABLE = $(BUILD)/appl.exe
all: $(OBJECTS) $(EXECUTABLE)
$(BUILD):
mkdir $(BUILD)
$(EXECUTABLE) : $(OBJECTS)
$(CC) $(OBJECTS) -o $@
.c.o:
$(CC) $(CFLAGS) -I$(LIBS) $< -o $@
phony: clean
clean:
rm $(BUILD)/*.o $(BUILD)/appl.exe
Questions are: how can i create /build
if not exist? and how to include external .h
in the $(CC) $(CFLAGS) -I$(LIBS) $< -o $@
, because -I$(LIBS)
does not work and i got following error ./src/main.c:4:20: fatal error: ExtLib.h: No such file or directory