c - Make - 无所事事 - 只有文件扩展名

标签 c compilation makefile

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

从文件名可以看出我对 c 非常陌生。

我希望进行以下编译:

make hello_world.c

但这会给出错误消息:make: Nothing to be done for hello_world.c.

如果我只是做 make hello_world 它就可以工作,即没有扩展名。

谁能解释这是为什么?

最佳答案

make 将目标作为其参数。如果您告诉它您想要创建 hello_word.c,它会查看该文件是否已经存在并且没有依赖项,并确定它是最新的 - 因此无需执行任何操作。

当你说make hello_world时,make找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'.

关于c - Make - 无所事事 - 只有文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16989435/

相关文章:

c - gethostbyname() 未知错误

c++ - 没有进位标志的大整数加法

android - 错误 : supertypes of the following classes cannot be resolved. 请确保您在类路径中有所需的依赖项

iphone - 尝试使用 Reachable.h/.m 检查互联网访问时出错

c - 包括 malloc_np.h 的便携方式

c++ - 我需要做什么才能获得在编译器优化代码中调用的函数?

parsing - 将 C 类型语法编译为自定义程序集

c - 库的 Makefile

powershell - GNU Make 和 Windows Powershell : "Remove-Item -ErrorAction Ignore" does not work

makefile - 删除 Makefile 中配方失败的目标