General Makefile, compile and generate

Create a new Makefile file, copy the following content, directly use the make command in the project to okay

make
make clean

CC = g++
CFLAGS = -pthread
TARGET = TEST
DIRS = .
FILES = $(foreach dir, $(DIRS), $(wildcard $(dir)/*.cpp))
OBJS = $(patsubst %.cpp, %.o, $(FILES))
TARGETNAME := TEST

$(TARGET):$(OBJS)
	$(CC) -o $(TARGET) $(OBJS) $(CFLAGS)
$(OBJS):%o:%cpp
	$(CC) -c $< -o $@ $(CFLAGS)

clean:
	-$(RM) $(TARGET) $(OBJS)

Guess you like

Origin blog.csdn.net/what951006/article/details/82837690