缺少分隔Makefile中? [英] Missing separator in Makefile?

查看:498
本文介绍了缺少分隔Makefile中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的Makefile不工作,我不知道发生了什么事。

  CC = GCC
CFLAGS = -Wall -g演示:
    $ {CC} $ {} CFLAGS -o demo.c演示
lib目录下:
    $ {CC} $ {} CFLAGS -o lib.c LIB
清洁:
    RM -f LIB演示

演示具有的主要功能和lib有一组在演示中使用的方法。

我添加了-C标志LIB。然而,当我运行make,我得到:

 的Makefile:5:***遗漏分隔符。停止。


解决方案

考虑到与错误的更新,请检查您对这些前行是什么 $ {CC} 命令。许多制作程序要求的真正的那把八个空格(例如)会打破他们的命令和编辑之前制表符。这往往比缺少分隔符的错误不是原因。

您可以看到,下面的谈话。在该文件中,还有 $(XYZZY)前四个空格

  XYZZY =回声
所有:
    $(XYZZY)打招呼

所以,当我做了,我得到了同样的错误,你:

  PAX>使
生成文件:3:***遗漏分隔符。停止。

但是,当我编辑,并把这些四个空格成一个标签,它工作正常:

  PAX>使
你好回声
你好


您还可以与你想的来源相结合的方式有问题文件一起。

如果没有 -c 标志 GCC ,它会尝试创建的每一个单独的可执行文件的这些命令,几乎可以肯定导致链接错误。你会需要这样的东西(简单):

  CC = GCC
CFLAGS = -Wall -g#只是编译/链接的所有文件中的一击。
演示:demo.c lib.c
   $ {CC} $ {} CFLAGS -o演示demo.c lib.c清洁:
    RM -f演示

或(稍微复杂):

  CC = GCC
CFLAGS1 = -Wall -g -c
CFLAGS2 = -g#链接两个目标文件一起。演示:demo.o lib.o
   $ {CC} $ {} CFLAGS2 -o演示demo.o lib.o#编译每个源文件的对象。demo.o:demo.c
   $ {CC} $ {} CFLAGS1 -o demo.o demo.clib.o:lib.c
   $ {CC} $ {} CFLAGS1 -o lib.o lib.c清洁:
    RM -f演示

与第一个解决方案的问题在于,它不必要编译两个项目即使只有一个是过时的。第二个解决方案是一个小更智能。

The following Makefile is not working and I am not sure what's going on.

CC = gcc
CFLAGS = -Wall -g

demo:
    ${CC} ${CFLAGS} demo.c -o demo
lib:
    ${CC} ${CFLAGS} lib.c -o lib
clean:
    rm -f lib demo

Demo has the main function and lib has a set of methods used in demo.

I added the -c flag to lib. However when I run make, I get:

Makefile:5: *** missing separator.  Stop.

解决方案

Given your update with the error, check what you have on the line before those ${CC} commands. Many make programs require a real tab character before the commands and editors that put in eight spaces (for example) will break them. That's more often than not the cause of the "Missing separator" errors.

You can see that with the following transcript. In the file, there are four spaces before the $(xyzzy):

xyzzy=echo
all:
    $(xyzzy) hello

So, when I make it, I get the same error as you:

pax> make
makefile:3: *** missing separator.  Stop.

But, when I edit it and turn those four spaces into a tab, it works fine:

pax> make
echo hello
hello


You also have a problem with the way you're trying to combine the source files together.

Without a -c flag to gcc, it will try to create a separate executable from each of those commands, almost certainly leading to linker errors. You're going to need something like (simple):

CC = gcc
CFLAGS = -Wall -g

# Just compile/link all files in one hit.
demo: demo.c lib.c
   ${CC} ${CFLAGS} -o demo demo.c lib.c

clean:
    rm -f demo

or (slightly more complex):

CC = gcc
CFLAGS1 = -Wall -g -c
CFLAGS2 = -g

# Link the two object files together.

demo: demo.o lib.o
   ${CC} ${CFLAGS2} -o demo demo.o lib.o

# Compile each source file to an object.

demo.o: demo.c
   ${CC} ${CFLAGS1} -o demo.o demo.c

lib.o: lib.c
   ${CC} ${CFLAGS1} -o lib.o lib.c

clean:
    rm -f demo

The problem with the first solution is that it unnecessarily compiles both programs even when only one is out of date. The second solution is a little more intelligent.

这篇关于缺少分隔Makefile中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆