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

我该怎么解决呢?


当前回答

如果您正在使用mcedit进行makefile编辑。你必须看到下面的标记。

其他回答

第4行以“空格,空格”开始,而不是“制表符”——没有其他。

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

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

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

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

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

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

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

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

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