Make - 没有什么可做的 - 只有文件扩展名

时间:2013-06-07 17:03:54

标签: c compilation makefile

我有一个简单的c程序 - hello_world.c

正如您可以通过文件名告诉我对c非常新。

我希望编译以下内容:

make hello_world.c

但是这会显示错误消息:make: Nothing to be done for hello_world.c.

如果我只是做make hello_world它就有效,即没有扩展名。

有人可以解释为什么会这样吗?

2 个答案:

答案 0 :(得分:7)

make将目标作为其参数。如果你告诉它你想要hello_word.c,它会看,看到那个文件已经存在且没有依赖关系,并且会决定它是最新的 - 因此没什么可做的。

当您说make hello_world时,请查找hello_word,找不到它,然后查找hello_world.o,找不到它,然后查找hello_world.c ,找到它,然后使用其隐式规则从中构建hello_world

您可以使用make -d查看make正在制定的决策。以下是make hello_world.c的示例 - 我已经裁掉了一堆来展示最后一部分,这是你关心的:

...
Considering target file `hello_world.c'.
 Looking for an implicit rule for `hello_world.c'.
 ...
 No implicit rule found for `hello_world.c'.
 Finished prerequisites of target file `hello_world.c'.
No need to remake target `hello_world.c'.
make: Nothing to be done for `hello_world.c'.

然后,make hello_world

...
Considering target file `hello_world'.
 File `hello_world' does not exist.
 Looking for an implicit rule for `hello_world'.
 Trying pattern rule with stem `hello_world'.
 Trying implicit prerequisite `hello_world.o'.
 Trying pattern rule with stem `hello_world'.
 Trying implicit prerequisite `hello_world.c'.
 Found an implicit rule for `hello_world'.
  Considering target file `hello_world.c'.
   Looking for an implicit rule for `hello_world.c'.
   Trying pattern rule with stem `hello_world'.
   ...
   No implicit rule found for `hello_world.c'.
   Finished prerequisites of target file `hello_world.c'.
  No need to remake target `hello_world.c'.
 Finished prerequisites of target file `hello_world'.
Must remake target `hello_world'.
cc     hello_world.c   -o hello_world
...
Successfully remade target file `hello_world'.

答案 1 :(得分:-2)

“Make”是一个用于构建具有多个源文件的非平凡项目的工具。如果您只想编译单个C文件,请使用C编译器。 cc通常作为C编译器的命令行名称提供,但gcc也是一个通用名称(可能引用相同的编译器)。