Skip to content

Instantly share code, notes, and snippets.

@zachwhaley
Last active December 24, 2023 01:48
Show Gist options
  • Save zachwhaley/9458612 to your computer and use it in GitHub Desktop.
Save zachwhaley/9458612 to your computer and use it in GitHub Desktop.
Simple C++ Makefile
CXXFLAGS = -g -Wall -Werror -std=c++11
LDLIBS =
PRGM = project
SRCS := $(wildcard *.cpp)
OBJS := $(SRCS:.cpp=.o)
DEPS := $(OBJS:.o=.d)
.PHONY: all clean
all: $(PRGM)
$(PRGM): $(OBJS)
$(CXX) $(OBJS) $(LDLIBS) -o $@
%.o: %.cpp
$(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
clean:
rm -rf $(OBJS) $(DEPS) $(PRGM)
-include $(DEPS)
@ArashPartow
Copy link

A comprehensive and easy to use C++ Makefile example can also be found here:

https://www.partow.net/programming/makefile/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment