C语言 Makefile:没有规则可以制作目标'*.o','*'需要。停止
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33315155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 12:11:05 来源:igfitidea点击:
Makefile: no rule to make target '*.o', needed by '*'. Stop
提问by Watercycle
I got the following error
我收到以下错误
make: *** No rule to make target `stretchy_buffer.o', needed by `tsh'. Stop
Trying to make this makefile
试图制作这个makefile
SRCS = stretchy_buffer.c def.c tsh_builtin_commands.c tsh_jobs.c tsh_main.c tsh_routines.c tsh_signals.c
OBJS = $(SRCS:.c=.o)
tsh: $(OBJS)
gcc -Wall -g -o tsh $(OBJS)
回答by cm161
You need to add following rule in your makefile:
您需要在 makefile 中添加以下规则:
CFLAGS = -Wall -g
%.o:%.c
gcc $(CFLAGS) $< -o $@
In your existing makefile, there is no rule specified for obtaining *.o from *.c files and, hence, the error is reported.
在您现有的 makefile 中,没有指定从 *.c 文件获取 *.o 的规则,因此会报告错误。

