gpt4 book ai didi

c++ - 当我们重复执行全部命令时会发生什么?

转载 作者:行者123 更新时间:2023-12-02 10:33:03 25 4
gpt4 key购买 nike

我试图了解makefile如何工作。这是一个示例makefile:

all: prog
x.o: x.cpp globals.hh
$(CC) -c x.cpp
y.o: y.cpp globals.hh
$(CC) -c y.cpp
prog: x.o y.o
$(LD) -o prog x.o y.o -lc

如果我执行 make file,然后在 x.cpp中进行一些更改,然后重复 make all,则重新运行哪些命令?

据我了解,以下命令将重新运行:
$(CC) -c x.cpp

-o prog x.o y.o -lc
而且,如果我改头文件,我认为当我再次制作全部文件时,这三个文件都将重新运行。

我对么?顺序是什么?

另外,我试图了解makefile的依赖关系图如何。我知道x.o,y.o和prog都是这里的目标。但是我的逻辑有意义吗?
enter image description here

最佳答案

没有将被重新运行。

创建x.oy.oprog时,它们中的每一个都将比其各自的输入文件新。
make不会重新制作比其输入新的文件,因此不会重新运行任何命令。

POSIX spec on make :

EXTENDED DESCRIPTION

The make utility attempts to perform the actions required to ensure that the specified targets are up-to-date. A target shall be considered up-to-date if it exists and is newer than all of its dependencies, or if it has already been made up-to-date by the current invocation of make (regardless of the target's existence or age). A target may also be considered up-to-date if it exists, is the same age as one or more of its prerequisites, and is newer than the remaining prerequisites (if any). The make utility shall treat all prerequisites as targets themselves and recursively ensure that they are up-to-date, processing them in the order in which they appear in the rule. The make utility shall use the modification times of files to determine whether the corresponding targets are out-of-date.

To ensure that a target is up-to-date, make shall ensure that all of the prerequisites of a target are up-to-date, then check to see if the target itself is up-to-date. If the target is not up-to-date, the target shall be made up-to-date by executing the rule's commands (if any). If the target does not exist after the target has been successfully made up-to-date, the target shall be treated as being newer than any target for which it is a prerequisite.

If a target exists and there is neither a target rule nor an inference rule for the target, the target shall be considered up-to-date. It shall be an error if make attempts to ensure that a target is up-to-date but the target does not exist and there is neither a target rule nor an inference rule for the target.

关于c++ - 当我们重复执行全部命令时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61561024/

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