这是我的makefile:

all:ll

ll:ll.c   
  gcc  -c  -Wall -Werror -02 c.c ll.c  -o  ll  $@  $<

clean :
  \rm -fr ll

当我尝试make clean或make make时,我得到这个错误:

:makefile:4: *** missing separator.  Stop.

我该怎么解决呢?


当前回答

如果你在eclipse中编辑你的Makefile:

Windows-> Preferences->General->Editor->Text Editors->Show Whitespace Characters -> Apply

或使用下面显示的快捷方式。

Tab用灰色“>>”表示,Space用灰色“.”表示,如下图所示。

其他回答

在VS Code中,在编辑你的Makefile时,只需点击“Space: 4”,并将其更改为tab。

默认情况下,您应该始终在制表符后写入命令,而不是空格。可以将其更改为带有. recipeprefix变量的另一个字符。

这适用于gcc行(行#4)。您需要在gcc之前插入tab。

也用rm -fr ll替换\rm -fr ll。在此命令之前也要插入制表符。

TLDR;

Makefile语法可能很古怪 如果你想让一行代码被解释为make代码,那么它只能用空格缩进。 如果您希望将一行代码解释为bash代码,则必须只使用制表符缩进

sometask:
  ifeq ($FOO,bar)  // this is make code. only spaces
    echo "foobar"  // this is bash code. only tabs
  endif            // again, this is make code. only spaces

从技术上讲,它是指示解释器的首缩进。

这是一个很老的问题,但我仍然想说一个使用vi/vim编辑器来可视化标签的选项。如果你安装了vi/vim,那么打开一个Makefile(例如vim Makefile)并输入:set list。这将显示插入的选项卡数量,如下所示,

 %-linux: force$
^I@if [ "$(GCC_VERSION)" = "2.96" ] ; then \$
^I^Iecho ===== Generating build tree for legacy $@ architecture =====; \$
^I^I$(CONFIGURE) $(CWD) $@ legacy; \$
^Ielse \$
^I^Iecho ===== Generating build tree for $@ architecture =====; \$
^I^I$(CONFIGURE) $(CWD) $@; \$
^Ifi$
^Icd build-$@;make$

使用.editorconfig自动修复选项卡:

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab