我正在尝试为一个项目生成一个简单的 makefile,但遇到了麻烦,因为我仍在适应它们。
我有一个文件夹,其中包含 3 个单独的文件,头文件 LinkedListAPI.h
, LinkedListAPI.c
和StructListDemo.c
。
必须使用标志:
-Wall -std=c11
最佳答案
这个看起来不错,但请记住用制表符替换所有缩进:
.PHONY: all clean
CFLAGS:=$(CFLAGS) -std=c11 -Wall
OBJ=./src
INCLUDE=./include
objStringListDemo=$(OBJ)/LinkedListAPI.o $(OBJ)/StringListDemo.o
objStructListDemo=$(OBJ)/LinkedListAPI.o $(OBJ)/StructListDemo.o
all: StringListDemo StructListDemo
StringListDemo: $(objStringListDemo) $(INCLUDE)/LinkedListAPI.h
${CC} -o $< $@
StructListDemo: $(objStructListDemo) $(INCLUDE)/LinkedListAPI.h
${CC} -o $< $@
%.o: %.c
${CC} $(CFLAGS) $< -o $@
clean:
rm -rf $(objStringListDemo) $(objStructListDemo) StringListDemo StructListDemo
关于c - 如何制作makefile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46171465/