c - 如何制作makefile?

标签 c makefile flags

我正在尝试为一个项目生成一个简单的 makefile,但遇到了麻烦,因为我仍在适应它们。

我有一个文件夹,其中包含 3 个单独的文件,头文件 LinkedListAPI.h , LinkedListAPI.cStructListDemo.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/

相关文章:

c# - 从枚举总和中取回值

Android关闭滚动动画

c - strtok 使用了错误的定界符

c - 从丢失的 TCP 连接中恢复传输

c - 为旧系统编写相对较大的线程应用程序

c++ - 删除后自动重建使用 -MMD 生成的依赖文件

c - 用于从 matlab 创建可执行 .mexa64 文件的 Makefile

linux - 带和不带 -p 标志的 Nmap,如何选择端口?

c - for循环内和for循环外递增

linux - 绘制由 make 生成的 DAG?