c - 具有多个主要功能的Makefile

标签 c makefile compiler-errors

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.

最佳答案

由于您提到了 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 ...

关于c - 具有多个主要功能的Makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46148215/

相关文章:

c++ - 传入字符串和整数的字符串函数

visual-studio - 将Unity3D项目从2019.2.12f1升级到2020.3.1f1后,Visual Studio Project中充斥着CS518错误

c++ - map<int, int>::iterator 的编译错误,与 operator = 不匹配

compilation - Fedora 18 上的内核编译错误(在 Macbook 上的 VirtualBox 上)

c++ - 基本 C++ 速度(初始化与添加)和比较速度

java - 从 JNI 调用 Java 方法

c - 使用 Makefile 进行简单编译?

c++ - 从 MinGW 链接到 OpenCV 的问题

c++ - Make 找不到我的 .so.2.4.8 文件

Makefile 依赖迭代通用规则