英文:
Why can't the result of make be shared across computers
问题
第一个问题是:为什么第二次运行时速度更快?
第二个问题是:为什么在将整个目录传输到另一台计算机之后(在已构建 make 后),make 命令仍然需要 4 小时才能完成,而不是 5-10 分钟?
英文:
I have a legacy work project which consists of 8000+ files. It includes the source code but also libraries so it can run independently.
However, when I run the make command the first time it takes roughly 4 hours, as opposed to executing the command the second time, after code additions, which is a lot faster and usually takes 5-10 minutes.
My first question is why is it faster the second time around?
Secondly, how come when the entire directory is transferred (after make has been built) to a different computer that the make command still takes 4 hours to complete and not 5-10 minutes?
答案1
得分: 5
GNU make的主要目的是编译代码,而且在没有更改代码的情况下进行编译。事实上,man make在描述的第一句话中就明确说明了:
make实用程序的目的是自动确定需要重新编译大型程序的哪些部分,并发出重新编译它们的命令。
再往下一点:
如果目标依赖于自上次修改目标以来已被修改的先决文件,或者如果目标不存在,make会更新目标。
这基本上解释了第二次以及后续编译的加速。不是一切都重新编译,而只有受代码更改影响的项目部分。
当你将源代码(和构建生成物)复制到另一台计算机时,修改时间很可能会不同。这会导致make重新编译所有内容。为防止这种情况发生,需要在复制时保留时间戳。
英文:
The main purpose of GNU make is to compile code and do so without recompiling code without changes. In fact, man make states right in the first sentence of the description:
> The purpose of the make utility is to determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them.
and a little bit further down:
> make updates a target if it depends on prerequisite files that have been modified since the target was last modified, or if the target does not exist.
This pretty much explains the speedup on second and following compilations. Not everything is compiled but only the parts of the project affected by the code changes.
When you copy your source code (and build artifacts) to another computer, the modification times will most likely be off. This will cause make to recompile everything. To prevent this from happening, preserve the time stamps when copying.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论