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

我该怎么解决呢?


当前回答

如果你的编辑器/IDE支持它(很可能是支持的!),帮你自己一个忙,让它成为你的.editorconfig的永久成员。

[Makefile]
indent_style = tab

其他回答

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

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

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

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

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

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

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

Make定义了开始每个食谱所需的TAB。每条规则的所有操作都由制表符标识。如果您喜欢使用制表符以外的字符作为食谱的前缀,则可以将. recipeprefix变量设置为另一个字符。

为了检查,我使用命令cat -e -t -v makefile_name。

它显示了以^I结尾的制表符和以$结尾的行。这两者对于确保依赖关系正确结束至关重要,并且制表符标记规则的操作,以便make实用程序容易识别它们。

例子:

Kaizen ~/so_test $ cat -e -t -v  mk.t
all:ll$      ## here the $ is end of line ...                   
$
ll:ll.c   $
^Igcc  -c  -Wall -Werror -02 c.c ll.c  -o  ll  $@  $<$ 
## the ^I above means a tab was there before the action part, so this line is ok .
 $
clean :$
   \rm -fr ll$
## see here there is no ^I which means , tab is not present .... 
## in this case you need to open the file again and edit/ensure a tab 
## starts the action part

如果你的编辑器/IDE支持它(很可能是支持的!),帮你自己一个忙,让它成为你的.editorconfig的永久成员。

[Makefile]
indent_style = tab

PyCharm的解决方案是安装一个Makefile支持插件:

打开首选项(cmd +,) 去插件->市场 搜索Makefile支持,安装并重新启动IDE。

这应该可以解决问题,并提供makefile的语法。