以下是我的makefile:
TARGET = prog
LIBS = -lm
CC = gcc
CFLAGS = -pthread -Wextra -Wall -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wwrite-strings -Waggregate-return -Wcast-qual -Wswitch-default -Wswitch-enum -Wconversion -Wunreachable-code
.PHONY: clean all default
default: $(TARGET) clean
all: default
OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
HEADERS = $(wildcard *.h)
%.o: %.c $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $@
.PRECIOUS: $(TARGET) $(OBJECTS)
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -Wall $(LIBS) -o $@
clean:
-rm -f *.o
使用上面的标志和目录中的一些文件,输出使得查找警告非常困难:
如何在每次调用 GCC 之间获取换行符?也许得到警告更突出?
答案 0 :(得分:1)
您可以将命令本身静音,并用更短的命令替换它。
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Times New Roman"
其他一些事情:
CPPFLAGS := -MMD -MP
CFLAGS := -pthread -Wextra -Wall -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wwrite-strings -Waggregate-return -Wcast-qual -Wswitch-default -Wswitch-enum -Wconversion -Wunreachable-code
LDLIBS := -lm
objects := $(patsubst %.c, %.o, $(wildcard *.c))
deps := $(objects:.o=.d)
.PHONY: all clean
prog: $(objects)
$(LINK.o) $^ $(LDLIBS) -o $@
%.o: %.c
@echo Compiling $<
@$(COMPILE.c) -o $@ $<
clean: ; $(RM) $(objects) $(deps)
-include $(deps)
至:=
=
是make的内置配方中使用的库的标准变量LDLIBS
设置为CC
,这应该是默认编译器的链接,通常不需要设置cc
CC
目标会破坏并行构建(default
),我不会打扰它-j
规则,只需将目标设为第一个规则all
和来源,手动指定它们通常更安全wildcard
,-MMD -MP
)include
设为$(RM)