Skip to content

Instantly share code, notes, and snippets.

@wenchy
Last active August 8, 2025 17:37
Show Gist options
  • Save wenchy/64db1636845a3da0c4c7 to your computer and use it in GitHub Desktop.
Save wenchy/64db1636845a3da0c4c7 to your computer and use it in GitHub Desktop.
Compile all .cpp files into one target under the current directory.
CC := g++
CFLAGS := -Wall -g
TARGET := test
# $(wildcard *.cpp /xxx/xxx/*.cpp): get all .cpp files from the current directory and dir "/xxx/xxx/"
SRCS := $(wildcard *.cpp)
# $(patsubst %.cpp,%.o,$(SRCS)): substitute all ".cpp" file name strings to ".o" file name strings
OBJS := $(patsubst %.cpp,%.o,$(SRCS))
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) -o $@ $^
%.o: %.cpp
$(CC) $(CFLAGS) -c $<
clean:
rm -rf $(TARGET) *.o
.PHONY: all clean
@RiDx18
Copy link

RiDx18 commented Aug 8, 2025

Help me , how did I make it opposite

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