Created
September 17, 2025 20:26
-
-
Save yapudpill/1d2126fd54452ad38582e1e826717279 to your computer and use it in GitHub Desktop.
Very simple makefiles for C and C++ projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 $@ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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