Andres Jaimes

A simple Makefile

By Andres Jaimes

Learning how to create a Makefile is one of those tasks every C/C++ programmer has to do. Since there are many good make tutorials on the web, I’m only going to share a simplistic makefile that you can use for your projects.

CFLAGS=-c -Wall -Iinclude
LDFLAGS=-lPocoFoundation -lPocoData
SOURCES=a.cpp b.cpp main.cpp

all: pre $(OBJECTS)
	g++ $(OBJECTS) -o build/main $(LDFLAGS)

	g++ $(CFLAGS) $< -o $@

	mkdir -p build

	rm -Rf build
	rm -f *.o


This Makefile assumes the following directory structure: All .cpp files are located inside a directory named “src”. All .h files are located inside a directory named “include”. As an example I’m linking against the PocoFoundation and the PocoData libraries, you should change those to the libraries your project uses.

There are so many additional things you can do to grow this basic Makefile. My objective here was to create something really basic that you can use as start point for your projects. I hope you find it useful.