gpt4 book ai didi

linux - 'all' 需要 Makefile 错误 : No rule to make target,。停止

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:37:57 25 4
gpt4 key购买 nike

我在这个目录中写了一个 Makefile:

    .
├── bin
│   └── obj
├── include
│   ├── globals.h
│   ├── ma.h
│   ├── mb.h
│   ├── mc.h
│   └── md.h
├── Makefile
├── Makefile.save
├── src
│   ├── ma.c
│   ├── main.c
│   ├── mb.c
│   ├── mc.c
│   └── md.c
└── test
├── main.c
└── main.o

我的 Makefile 如下:

CFLAGS := -Wall -g -pedantic --std=c99

objs := bin/obj/ma.o bin/obj/mb.o bin/obj/mc.o bin/obj/md.o bin/obj/main.o

all: $(objs)

%.o: %.c
gcc -c $< -o $@ $(CFLAGS)

但是我不能执行make order;该程序给我这个错误:

make: *** No rule to make target 'bin/obj/ma.o', needed by 'all'.  Stop.

有人有想法吗?

最佳答案

您需要告诉 make 以某种方式将源文件名映射到目标文件。这可能有效:

bin/obj/%.o: src/%.c
gcc -c $< -o $@ $(CFLAGS)

您必须对 test 子目录分别执行相同的操作。

对于缺少的头文件头,你将不得不在命令行中添加-Iinclude(最好在不同的变量中而不是在CFLAGS中,这样它仍然可以从命令行覆盖 CFLAGS

关于linux - 'all' 需要 Makefile 错误 : No rule to make target,。停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46364720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com