“没有什么可以为makefile做的”消息

时间:2011-08-14 18:27:44

标签: c makefile

我有以下文件:

Child.c,Cookie.c,Cookie.h,CookieMonster.c,Jar.c,Jar.h,Milk.c,Milk.h

和以下makefile,名为makePractice,它应该创建两个可执行文件,Child和CookieMonster。

makefile:

CC = gcc    # the compiler
CFLAGS = -Wall  # the compiler flags
ChildObjects = Jar.o    # object files for the Child executable
CookieMonsterObjects = Jar.o Milk.o     #object files for the CookieMonster executable

all: Child CookieMonster    # the first target. Both executables are created when 
                # 'make' is invoked with no target

# general rule for compiling a source and producing an object file
.c.o:
    $(CC) $(CFLAGS) -c $<

# linking rule for the Child executable
Child: $(ChildObjects)
    $(CC) $(CFLAGS) $(ChildObjects) -o Child

# linking rule for the CookieMonster executable
CookieMonster: $(CookieMonsterObjects)
    $(CC) $(CFLAGS) $(CookieMonsterObjects) -o CookieMonster

# dependance rules for the .o files

Child.o: Child.c Cookie.h Jar.h

CookieMonster.o: CookieMonster.c Cookie.h Jar.h Milk.h

Jar.o: Jar.c Jar.h Cookie.h

Milk.o: Milk.c Milk.h

Cookie.o: Cookie.c Cookie.h

# gives the option to delete all the executable, .o and temporary files

clean: 
    rm -f *.o *~

当我尝试使用makefile创建可执行文件时,通过在shell中运行以下行

make -f makePractice

我收到以下消息:

make: Nothing to be done for `makefile'.

我不明白什么是错的......

2 个答案:

答案 0 :(得分:15)

如果未在命令行上指定目标,则Make默认使用makefile中定义的第一个目标。就你而言,那是makefile:。但这没有任何作用。所以只需删除makefile:

答案 1 :(得分:5)

您的命令行没有告诉make您想要制作什么,因此它默认尝试在makefile中创建第一个显式命名的目标。这恰好是makefile,在第一行。

  

生成文件:

由于没有依赖关系,因此没有理由做任何事情来重制该文件。因此make退出,乐于听从你的愿望。