简单 Makefile 模板
# Makefile for compiling C program
# Compiler
CC = gcc
# Compiler flags
CFLAGS = -Wall -g
# Target executable name
TARGET = exe
# Source files
SOURCES = *.c
# Header files
HEADERS = *.h
# Object files
OBJECTS = $(SOURCES:.c=.o)
# Default target
all: $(TARGET)
./$(TARGET)
# Link object files to create executable
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -o $(TARGET)
# Compile source files to object files
%.o: %.c $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $@
# Run the executable
run: $(TARGET)
./$(TARGET)
# Clean build artifacts
clean:
rm -f $(OBJECTS) $(TARGET)
# Rebuild everything
rebuild: clean all
.PHONY: all clean rebuild run
执行 make 进行编译,边以后会直接运行
make rebuild: 删掉编译文件并重新编译
make run:运行可执行文件
make all:重新编译
make clean:清除中间文件

浙公网安备 33010602011771号