gpt4 book ai didi

c++ - 预编译头如何减少编译时间

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:31:27 26 4
gpt4 key购买 nike

我使用预编译 header 已有一段时间,并被告知(并看到)它们如何减少编译时间。但我真的很想知道发生了什么(幕后),这样可以加快我的编译速度。

因为据我所知,在 .cpp 中添加未使用的 include 会减慢编译时间,并且头文件可能包含大量未使用的 .cpp 头文件。

那么预编译头如何让我的编译速度更快呢?

最佳答案

来自 http://gamesfromwithin.com/the-care-and-feeding-of-pre-compiled-headers谢谢 (@Pablo)

A C++ compiler operates on one compilation unit (cpp file) at the time. For each file, it applies the pre-preprocessor (which takes care of doing all the includes and “baking” them into the cpp file itself), and then it compiles the module itself. Move on to the next cpp file, rinse and repeat. Clearly, if several files include the same set of expensive header files (large and/or including many other header files in turn), the compiler will be doing a lot of duplicated effort.

The simplest way to think of pre-compiled headers is as a cache for header files. The compiler can analyze a set of headers once, compile them, and then have the results ready for any module that needs them.

关于c++ - 预编译头如何减少编译时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8291550/

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