zoukankan      html  css  js  c++  java
  • make error: 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 :$
       
    m -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标记等

    查看前20个字符,每行显示10个字符:

    $ xxd -l 20 -c 10 makefile
    00000000: 616c 6c3a 2068 656c 6c6f  all: hello
    0000000a: 2e6f 0a0a 6865 6c6c 6f2e  .o..hello.
    
  • 相关阅读:
    python 协程之Greenlet
    python 协程
    python 多进程通信之Manger
    python 多线程通信之Queue
    python 多进程
    python threading之queue
    python threading之同步条件(Event)
    python threading之条件变量同步(condition)
    python之字符串常用方法
    python之字典操作
  • 原文地址:https://www.cnblogs.com/minding/p/11864869.html
Copyright © 2011-2022 走看看