makefile:4: *** missing separator. Stop

2019-01-01 16:37发布

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?

标签: c makefile
8条回答
君临天下
2楼-- · 2019-01-01 17:17

Its pretty old question but still I would like say about one more option using vi/vim editor to visualize the tabs. If you have vi/vim installed then open a Makefile (e.g. vim Makefile) and enter :set list. This will show number of tabs inserted as below,

 %-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$
查看更多
泛滥B
3楼-- · 2019-01-01 17:20

If you are using mcedit for makefile edit. you have to see the following mark. enter image description here

查看更多
零度萤火
4楼-- · 2019-01-01 17:21

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

查看更多
像晚风撩人
5楼-- · 2019-01-01 17:29

The key point was "HARD TAB" 1. Check whether you used TAB instead of whitespace 2. Check your .vimrc for "set tabstop=X"

查看更多
呛了眼睛熬了心
6楼-- · 2019-01-01 17:30

This is because tab is replaced by spaces. To disable this feature go to

gedit->edit->preferences->editor

and remove check for

"replace tab with space"

查看更多
初与友歌
7楼-- · 2019-01-01 17:33

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

查看更多
登录 后发表回答