【问题标题】:How to make a makefile? [duplicate]如何制作makefile? [复制]
【发布时间】:2018-02-20 15:01:19
【问题描述】:

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

我有一个文件夹,其中包含 3 个单独的文件,头文件 LinkedListAPI.hLinkedListAPI.cStructListDemo.c

必须使用标志:

-Wall -std=c11 

【问题讨论】:

    标签: c makefile flags


    【解决方案1】:

    这个看起来不错,但记得用 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-24
      • 2011-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多