【发布时间】:2018-02-20 15:01:19
【问题描述】:
我正在尝试为一个项目生成一个简单的 makefile,但遇到了麻烦,因为我还在习惯它们。
我有一个文件夹,其中包含 3 个单独的文件,头文件 LinkedListAPI.h、LinkedListAPI.c 和 StructListDemo.c。
必须使用标志:
-Wall -std=c11
【问题讨论】:
我正在尝试为一个项目生成一个简单的 makefile,但遇到了麻烦,因为我还在习惯它们。
我有一个文件夹,其中包含 3 个单独的文件,头文件 LinkedListAPI.h、LinkedListAPI.c 和 StructListDemo.c。
必须使用标志:
-Wall -std=c11
【问题讨论】:
这个看起来不错,但记得用 Tab 替换 all 缩进:
.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
【讨论】: