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/