【问题标题】:Makefile with multiple main functions具有多个主要功能的 Makefile
【发布时间】:2017-09-11 04:31:30
【问题描述】:
all: program1 program2

program1: StringListDemo.o
    gcc -Wall -std=c11 -Iinclude src/StringListDemo.c src/LinkedListAPI.c -o program1

program2: StructListDemo.o
    gcc -Wall -std=c11 -Iinclude src/StructListDemo.c src/LinkedListAPI.c -o program2

试图用两个具有主要功能的文件编译文件夹,但一直出错。

make: *** No rule to make target `StringListDemo.o', needed by `program1'.  Stop.

【问题讨论】:

  • 如果你编译命令需要一个.c 文件,你为什么要依赖.o?
  • 从您的标题来看,只有将多个程序目标添加到您的 makefile 中时,您才会遇到问题。您确定它适用于 1 个程序吗?

标签: c makefile compiler-errors


【解决方案1】:

既然你提到了StringListDemo.o,但没有给出任何规则,make 会寻找一个告诉如何更新它的implicit rule。换句话说,make 查找当前目录中显然不存在的StringListDemo.c 文件。但是,您还提到了src/StringListDemo.c,而program1 目标显然取决于它。所以你应该把先决条件列表中的StringListDemo.o改为src/StringListDemo.o:

program1: src/StringListDemo.o

同样的逻辑也适用于program2。


如果src/StringListDemo.c 应该使用特殊选项(不同于默认值)编译,则显式添加StringListDemo.o 目标,例如:

StringListDemo.o: src/StringListDemo.c
    gcc ...

【讨论】:

    猜你喜欢
    • 2012-07-18
    • 2015-01-24
    • 1970-01-01
    • 2019-01-11
    • 1970-01-01
    • 2011-02-07
    • 2018-09-24
    • 2020-08-12
    • 1970-01-01
    相关资源
    最近更新 更多