Mar*_*ace 4 c makefile compilation
我有一个简单的c程序 - hello_world.c
你可以通过文件名来判断我对c非常新.
我希望编译以下内容:
make hello_world.c
Run Code Online (Sandbox Code Playgroud)
但这会给出一条错误消息: 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'.
Run Code Online (Sandbox Code Playgroud)
然后,为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'.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4538 次 |
| 最近记录: |