Skip to content

Instantly share code, notes, and snippets.

@jacksonhorton
Created October 12, 2022 02:39
Show Gist options
  • Save jacksonhorton/741f640dd4101d6b3f820e16a7cf8e3e to your computer and use it in GitHub Desktop.
Save jacksonhorton/741f640dd4101d6b3f820e16a7cf8e3e to your computer and use it in GitHub Desktop.
Makefile for a main.cpp file with one class header/implementation dependency
# This makefile is for a main file with one external header and implementation file (.h/.cpp)
## Variables
# target is the name of the binary executable
TARGET=main
# class is the name of the class to include in the target.cpp file
CLASS=Vector
# compiler is g++
CC=g++
# compile with all warnings and extras
CFLAGS=-g -Wall -Wextra
## Targets
# compile everything
all: $(TARGET)
# this target compiles the binary executable; it requires all of the object code files from the headers and other files
$(TARGET): $(TARGET).o $(CLASS).o
$(CC) $(CFLAGS) -o $(TARGET) $(TARGET).o $(CLASS).o
$(TARGET).o: $(TARGET).cpp $(CLASS).cpp
$(CC) $(CFLAGS) -c $(TARGET).cpp
$(CLASS).o: $(CLASS).cpp
$(CC) $(CFLAGS) -c $(CLASS).cpp
# remove all temp files, machine code, binary files, etc.
clean:
$(RM) *.o *~ *# $(TARGET)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment