Makefile-丢失的分隔符

可能的复制品:
发生错误: 缺少分隔符

在 makefile 中包含以下代码:

PROG = semsearch
all: $(PROG)
%: %.c
gcc -o $@ $< -lpthread


clean:
rm $(PROG)

和错误

missing separator. stop.

有人能帮帮我吗?

153320 次浏览

You need to precede the lines starting with gcc and rm with a hard tab. Commands in make rules are required to start with a tab (unless they follow a semicolon on the same line). The result should look like this:

PROG = semsearch
all: $(PROG)
%: %.c
gcc -o $@ $< -lpthread


clean:
rm $(PROG)

Note that some editors may be configured to insert a sequence of spaces instead of a hard tab. If there are spaces at the start of these lines you'll also see the "missing separator" error. If you do have problems inserting hard tabs, use the semicolon way:

PROG = semsearch
all: $(PROG)
%: %.c ; gcc -o $@ $< -lpthread


clean: ; rm $(PROG)