makefile - sandbox example

Always start learning make with a sandbox so you can get clear about how make works.

Make your make file like this:

all: test main.o: main.cpp main.h %.o: %.cpp $(CC) -c $< -o $@ test: main.o life.o $(CC) main.o life.o -o test clean: rm -rf *.o test

It’s important the “all” rule goes at the top.

For your demo files main.h and life.cpp can be empty files - try doing “touch main.h life.cpp”.

For main.cpp use this:

#include "main.h" #include <stdio.h> int main(){ printf("Hello world of C!\n"); return 0; }