本文翻译自:makefile:4: *** missing separator. Stop
This is my makefile: 这是我的makefile:
all:ll
ll:ll.c
gcc -c -Wall -Werror -02 c.c ll.c -o ll $@ $<
clean :
\rm -fr ll
When I try to make clean
or make make
, I get this error: 当我尝试make clean
或make make
,出现以下错误:
:makefile:4: *** missing separator. Stop.
How can I fix it? 我该如何解决?
#1楼
参考:https://stackoom.com/question/192j4/makefile-缺少分隔符-停止
#2楼
You should always write command after a "tab" and not white space. 您应该始终在“制表符”之后而不是空格后写命令。
This applies to "gcc" line (line #4) in your case. 在您的情况下,这适用于“ gcc”行(第4行)。 You need to insert tab before gcc. 您需要在gcc之前插入制表符。
Also replace \\rm -fr ll with "rm -fr ll". 还将\\ rm -fr ll替换为“ rm -fr ll”。 Insert tabs before this command too 在此命令之前也插入标签
#3楼
makefile has a very stupid relation with tabs, all actions of every rule are identified by tabs ...... and No 4 spaces don't make a tab, only a tab makes a tab... makefile与选项卡之间的关系非常愚蠢,每个规则的所有动作都由选项卡......标识,并且没有4个空格不会构成选项卡,只有选项卡可以构成选项卡...
to check I use the command cat -e -t -v makefile_name
检查我是否使用命令cat -e -t -v makefile_name
It shows the presence of tabs with ^I
and line endings with $
both are vital to ensure that dependencies end properly and tabs mark the action for the rules so that they are easily identifiable to the make utility..... 它显示了带有^I
的制表符和带有$
行尾两者的存在对于确保依存关系正确结束以及制表符标记规则的动作至关重要,以便使make实用程序易于识别它们是至关重要的。
Example: 例:
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
hope this helps !! 希望这可以帮助 !!
#4楼
关键点是“ HARD TAB” 1.检查您是否使用TAB而不是空格2.检查您的.vimrc中的“ set tabstop = X”
#5楼
This is because tab is replaced by spaces. 这是因为制表符被空格代替。 To disable this feature go to 要禁用此功能,请转到
gedit->edit->preferences->editor gedit-> edit-> preferences-> editor
and remove check for 并删除检查
" replace tab with space " “ 用空格替换选项卡 ”
#6楼
在VS Code上,只需单击右下角的“空格:4”,然后在编辑Makefile时将其更改为选项卡。