The makefile is a text file that contains the recipe for building your program. It usually resides in the same directory as the sources, and it is usually called Makefile . Each one of these commands should be a separate rule in a makefile.

CC=g++
CFLAGS=-c -Wall -std=c++17
LDFLAGS=
SOURCES=main.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=ExampleProject

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
	$(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
	$(CC) $(CFLAGS) $< -o $@

clean:
	rm -rf *.o $(EXECUTABLE)

From above, the compiler is g++ and the flags for compiling are -c -Wall -std=c++17. The source files for the project are listed in the SOURCES variable. The object files are generated from the source files using the .cpp.o rule. The executable is generated from the object files using the $(EXECUTABLE) target. The clean target removes the object files and the executable. To build the project, simply run make. To clean the project, run make clean.