make 抱怨“缺少分隔符(你是说 TAB 吗?)”

Rin*_*ael 10 compiling make

在尝试安装som_pak-3.1-NAcMoS.tar.gz文件时,我使用了以下命令:

$ tar xvf som_pak-3.1-NAcMoS.tar.gz
$ cd som_pak-3.1
$ cp makefile.unix makefile
$ make
$ cd ..
$ ln -s som_pak-3.1 $NACMOS_HOME/som_pak
Run Code Online (Sandbox Code Playgroud)

但是在执行make命令时,我收到以下错误:

*缺少分隔符(您是指 TAB 而不是 8 个空格吗?)。停止。

  • 谁能告诉我错误的原因?
  • 是否需要包含任何软件包?

slm*_*slm 17

您遇到的错误:

*** 缺少分隔符(您是指 TAB 而不是 8 个空格吗?)。停止。

意味着makefile包含空格而不是制表符。该make实用程序是出了名的挑剔有关使用Space替代Tab。所以很可能makefile包含Space在文件中规则节的开头。

例子

假设我有以下 3 个.c文件:

你好ç
char *
hello() 
{
  return "Hello";
}
Run Code Online (Sandbox Code Playgroud) 世界.c
char *
world() 
{
  return "world";
}
Run Code Online (Sandbox Code Playgroud) 主文件
#include <stdio.h>

/* Prototypes. */
char *hello();
char *world();

int
main(int argc, char *argv[]) 
{
    printf("%s, %s!\n", hello(), world());
    return 0;
}    
Run Code Online (Sandbox Code Playgroud)

说我有以下几点Makefile

# The executable 'helloworld' depends on all 3 object files
helloworld: main.o hello.o world.o
        cc -o helloworld main.o hello.o world.o # Line starts with TAB!

# Build main.o (only requires main.c to exist)
main.o: main.c
        cc -c main.c # Line starts with TAB!

# Build hello.o (only requires hello.c to exist)
hello.o: hello.c
        cc -c hello.c # Line starts with TAB!

# Build world.o (only requires world.c to exist)
world.o: world.c
        cc -c world.c # Line starts with TAB!

#  Remove object files, executables (UNIX/Windows), Emacs backup files, 
#+ and core files
clean:
        rm -rf  *.o helloworld *~ *.core core # Line starts with TAB!
Run Code Online (Sandbox Code Playgroud)

现在我们尝试构建一个目标

当我针对目标运行它时helloworld

$ make helloworld
makefile:3: *** missing separator (did you mean TAB instead of 8 spaces?).  Stop.
Run Code Online (Sandbox Code Playgroud)

看起来熟悉?

解决问题

您可以通过将 更改Spaces为实际Tab字符来解决此问题。我曾经vim修复过我的文件。只需打开它:

$ vim makefile
Run Code Online (Sandbox Code Playgroud)

然后在其中运行此命令:

:%s/^[ ]\+/^I/
Run Code Online (Sandbox Code Playgroud)

注意: ^I是一个特殊字符。与+ - +相比,键入^后跟I将被不同地解释。CtrlVCtrlI

这会将所有以 1 或更多开头的行替换Spaces为实际的Tab.

现在,当我重新运行helloworld目标时:

$ make helloworld
cc -c main.c # Line starts with TAB!
cc -c hello.c # Line starts with TAB!
cc -c world.c # Line starts with TAB!
cc -o helloworld main.o hello.o world.o # Line starts with TAB!
Run Code Online (Sandbox Code Playgroud)

参考