makefile:4: *** missing separator. Stop

This is my 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:

:makefile:4: *** missing separator.  Stop.

How can I fix it?


makefile has a very stupid relation with tabs , all actions of every rule are identified by tabs ...... and No 4 spaces dont make a tab , only a tab makes a tab...

to check i use the command 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.....

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 !!


You should always write command after a "tab" and not white space.

This applies to "gcc" line (line #4) in your case. You need to insert tab before gcc.

Also replace rm -fr ll with "rm -fr ll". Insert tabs before this command too


在VS Code上,只需点击直角上的“Space:4”,并在编辑Makefile时将其更改为Tab。

链接地址: http://www.djcxy.com/p/61444.html

上一篇: makefile:为什么这个简单的makefile只处理第一个源文件?

下一篇: makefile:4:***缺少分隔符。 停止