Skip to content

Instantly share code, notes, and snippets.

@yapudpill
Created September 17, 2025 20:26
Show Gist options
  • Select an option

  • Save yapudpill/1d2126fd54452ad38582e1e826717279 to your computer and use it in GitHub Desktop.

Select an option

Save yapudpill/1d2126fd54452ad38582e1e826717279 to your computer and use it in GitHub Desktop.
Very simple makefiles for C and C++ projects
# A simple Makefile for simple C projects, made by Yapudpil.
# For it to work properly, use the following project structure :
# .
# |-- scr/
# | |-- <.c files>
# |-- include/
# | |-- <.h files>
# |-- <main>.c
# |-- Makefile
# change accordingly to what you need
CC := gcc
CFLAGS := --std=c++11 -Wall -Iinclude
objects := $(patsubst src/%.c,build/%.o,$(wildcard src/*.c))
main := $(basename $(wildcard *.c))
.PHONY: clean all
all: $(main)
clean:
rm -rf build $(main)
build:
mkdir build
build/%.o: src/%.c include/%.h build
$(CC) -c $(CFLAGS) $< -o $@
$(main): %: %.c $(objects)
$(CC) $(CFLAGS) $^ -o $@
# A simple Makefile for simple C++ projects, made by Yapudpil.
# For it to work properly, use the following project structure :
# .
# |-- scr/
# | |-- <.cpp files>
# |-- include/
# | |-- <.hpp files>
# |-- <main>.cpp
# |-- Makefile
# change accordingly to what you need
CXX := g++
CXXFLAGS := --std=c++11 -Wall -Iinclude
objects := $(patsubst src/%.cpp,build/%.o,$(wildcard src/*.cpp))
main := $(basename $(wildcard *.cpp))
.PHONY: clean all
all: $(main)
clean:
rm -rf build $(main)
build:
mkdir build
build/%.o: src/%.cpp include/%.hpp build
$(CXX) -c $(CXXFLAGS) $< -o $@
$(main): %: %.cpp $(objects)
$(CXX) $(CXXFLAGS) $^ -o $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment