这是我的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.
我该怎么修好呢?
make与制表符的关系非常愚蠢。每个规则的所有操作都由选项卡标识。还有,不,四个空格不是一个制表符。只有一个标签才有一个标签。
为了进行检查,我使用命令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
在VS代码上,只需单击右角的“space:4”,然后在编辑您的makefile时将其更改为tab。
您应该始终在制表符之后写入命令,而不是空白。
这适用于您的gcc
行(第4行)。您需要在gcc
之前插入tab。
还要将\rm-Fr ll
替换为rm-Fr ll
。在此命令之前也插入选项卡。