这是我的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.

我该怎么解决呢?


当前回答

默认情况下,您应该始终在制表符后写入命令,而不是空格。可以将其更改为带有. 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

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

当你在VSCode中创建Makefile时,你应该设置Tab Size: 4。

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

root = true

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

[Makefile]
indent_style = tab

关键点是“HARD TAB”

检查是否使用TAB而不是空格 检查.vimrc中的set tabstop=X

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

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

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

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