gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:29:41 24 4
gpt4 key购买 nike

我有一个简单的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com