makefile:4: *** missing separator. Stop

  • Question:

This is my makefile:

all: hello.o

hello.exe: hello.o
    gcc -o hello.exe hello.o

hello.o: hello.c
    gcc -c hello.c

clean:
    rm hello.o hello.exe

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 don't 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 !!


makefile中要在shell中执行的命令必须要用tab开头,而make语句用空格即可

:

第8行和第10行用tab

ifneq ($(KERNELRELEASE),)
    obj-m += module.o
else
    PWD := $(shell pwd)
    KVER := $(shell uname -r)
    KDIR := /lib/modules/$(KVER)/build
all:
        $(MAKE)    -C $(KDIR) M= $(PWD)
clean:
        rm -rf *.o *.mod.c *.ko *.symvers *.order *.makers
endif

其他问题,如编码格式,中文、日文字符,文件开头有BOM标记等

xxd -l 16 makefile

猜你喜欢

转载自www.cnblogs.com/minding/p/11864869.html
今日推荐