Makefile:没有规则来制作'*'所需的目标'*.o'.停止

Wat*_*cle 1 c makefile gnu-make

我收到以下错误

make: *** No rule to make target `stretchy_buffer.o', needed by `tsh'.  Stop
Run Code Online (Sandbox Code Playgroud)

试图制作这个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)
Run Code Online (Sandbox Code Playgroud)

小智 6

您需要在makefile中添加以下规则:

CFLAGS = -Wall -g

%.o:%.c
    gcc $(CFLAGS) $< -o $@
Run Code Online (Sandbox Code Playgroud)

在现有的makefile中,没有指定从*.c文件中获取*.o的规则,因此会报告错误.