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

其他回答

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

这是因为制表符被空格取代。 若要禁用此功能,请转到

中- >编辑- >首选项- >编辑器

并删除检查

"用空格替换制表符"

这是一个很老的问题,但我仍然想说一个使用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$

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

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

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