C语言 “对 makefile 无事可做”消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7058805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Nothing to be done for makefile" message
提问by Moshe
I have the following files:
我有以下文件:
Child.c , Cookie.c , Cookie.h , CookieMonster.c , Jar.c , Jar.h, Milk.c , Milk.h
Child.c , Cookie.c , Cookie.h , CookieMonster.c , Jar.c , Jar.h, Milk.c , Milk.h
and the following makefile, named makePractice, which is supposed to create two executables, Childand CookieMonster.
以及以下名为 的生成文件,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 *~
When I try to use the makefile to create the executables, by running the following line in the shell
当我尝试使用 makefile 创建可执行文件时,通过在 shell 中运行以下行
make -f makePractice
I get the following message:
我收到以下消息:
make: Nothing to be done for `makefile'.
I don't understand what's wrong...
我不明白有什么问题...
回答by Oliver Charlesworth
If you don't specify a target on the command-line, Make uses the first target defined in the makefile by default. In your case, that is makefile:. But that doesn't do anything. So just remove makefile:.
如果您没有在命令行中指定目标,Make 默认使用 makefile 中定义的第一个目标。在你的情况下,那就是makefile:。但这没有任何作用。所以只需删除makefile:.
回答by hmakholm left over Monica
Your command line does not tell makewhat you want to be made, so it defaults to trying to make the first explicitly named target in the makefile. That happens to be makefile, at the very first line.
你的命令行不会告诉make你想要做什么,所以它默认尝试在 makefile 中创建第一个明确命名的目标。这恰好是makefile,在第一行。
makefile:
生成文件:
Since there are no dependencies, there is no reason to do anything to remake that file. Therefore makeexits, happy at having obeyed your wish.
由于没有依赖项,因此没有理由重新制作该文件。因此make退出,高兴于服从了你的愿望。

