本文介绍了什么是“全部"?在makefile中代表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了一些有关Makefile的教程,但是对我来说,目标全部"代表什么以及它的作用还不清楚.

I read some tutorials concerning Makefiles but for me it is still unclear for what the target "all" stands for and what it does.

有什么想法吗?

推荐答案

据Makefile理解,构建包含许多目标.例如,要构建一个项目,您可能需要

A build, as Makefile understands it, consists of a lot of targets. For example, to build a project you might need

  1. 从file1.c中构建file1.o
  2. 从file2.c中构建file2.o
  3. 从file3.c中构建file3.o
  4. 从file1.o和file3.o构建可执行文件1
  5. 从file2.o中构建可执行文件2

如果使用makefile实现此工作流程,则可以分别创建每个目标.例如,如果您写了

If you implemented this workflow with makefile, you could make each of the targets separately. For example, if you wrote

make file1.o

它只会在必要时构建该文件.

it would only build that file, if necessary.

all的名称不固定.这只是一个常规名称; all目标表示如果您调用它,make将构建 all 进行完整构建所需的内容.通常这是一个虚拟目标,它不创建任何文件,而仅依赖于其他文件.对于上面的示例,构建 all 必需的是构建可执行文件,其他文件作为依赖项被拉入.因此,在makefile中,它看起来像这样:

The name of all is not fixed. It's just a conventional name; all target denotes that if you invoke it, make will build all what's needed to make a complete build. This is usually a dummy target, which doesn't create any files, but merely depends on the other files. For the example above, building all necessary is building executables, the other files being pulled in as dependencies. So in the makefile it looks like this:

all: executable1 executable2

all目标通常是makefile中的第一个目标,因为如果仅在命令行中编写make而不指定目标,它将构建第一个目标.而且您希望它是all.

all target is usually the first in the makefile, since if you just write make in command line, without specifying the target, it will build the first target. And you expect it to be all.

all通常也是.PHONY的目标.在此处了解更多信息.

all is usually also a .PHONY target. Learn more here.

这篇关于什么是“全部"?在makefile中代表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 02:53