Skip to main content

Makefile

  • Stores the recipe on how to build the program
  • Analyzes dependencies and only recompiles what is really needed

Consists of rules like:

target: dependencies
command
command
command
  • Use one TAB for indenting not space
make -f <makefile>
  • Example Makefile
CC = c++
CPPFLAGS = -std=c++14 -g -Wall -I../include
LDFLAGS = -L../lib
OBJS = build/*.o

build/main: build/main.o
$(CC) build/main.o $(LDFLAGS) -o build/main

build/main.o: src/*.cpp
@mkdir -p build
$(CC) $(CPPFLAGS) -c src/main.cpp -o build/main.o

clean:
rm -r build

Source