如何有效地使用precompiled头(使用/ YC和俞选项)? [英] How to use precompiled headers efficiently (using /Yc and Yu options)?

查看:148
本文介绍了如何有效地使用precompiled头(使用/ YC和俞选项)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用的编译的Visual Studio 2003(VC71)。
为了减少编译时间我们改变了构建脚本这样就产生了precompiled头(.PCH)文件每个CPP文件。

We are using Visual Studio 2003 (VC71) for compilation. In order to reduce the compile time we changed the build script such that it generates the precompiled header (.pch) file for each CPP file.

在生成文件中使用的选项:

The option used in makefile:

/Yc"StdAfx.h"
/Fp"StdAfx.pch"

通过这个编译时的目标得到了降低30%。但是,任何人都可以帮助我理解它是如何减少甚至当如何产生PCH文件每次每个CPP文件的编译,编译器的时间。

With this the compile time for the target got reduced by 30%. But could anyone help me to understand how is it reducing the compiler time even when the pch file is getting generated every time for compilation of each CPP file.

此外,有正确的方法?我们是否应该使用YC和玉结合?
我无法使用/于选项作为PCH文件应至少一次genrated。

Also, is it the right approach? Should we use Yc and Yu combination ? I cannot use /Yu option as the pch file should be genrated at least once.

推荐答案

让我们假设你有你用,你知道会不会改变标题的列表。例如,C头文件或C ++头文件,或升压头,等等。

The problem

Let's say you have a list of headers you use that you know won't change. For example, the C headers, or the C++ headers, or Boost headers, etc..

阅读他们每个CPP文件编译需要时间,这是不是因为编译器正在读取相同的头,一遍又一遍,并产生同样的编译的结果对于那些相同的头,连连生产时间。

Reading them for each CPP file compilation takes time, and this is not productive time as the compiler is reading the same headers, again and again, and producing the same compilation result for those same headers, again and again.

应该有某种方式来告诉编译器的头总是相同的,并且缓存其编译的结果,而不是一次又一次地重新编译他们的,不是吗?

There should be some way to tell the compiler those headers are always the same, and cache their compiled result instead of recompiling them again and again, no?

在pre-编译头文件考虑到这一点,因此,所有你需要的是:

The Pre-Compiled Headers takes that into account, so all you need is to:


  1. 把所有这些共同的和不变的包括一个头文件(例如,StdAfx.h中)

  2. 有一个空位CPP文件(比如说,StdAfx.cpp),包括仅此一个头文件

而现在,你需要的是告诉编译器StdAfx.cpp是包括常见的和不变的头空源。

And now, what you need is tell the compiler that StdAfx.cpp is the empty source that includes the common and unchanging headers.

这是那里的标志/使用YC和/瑜:

This is where the flags /Yc and /Yu are used:


  • 编译StdAfx.cpp使用/ YC标志文件

  • 编译所有其他cpp文件与/羽旗

和编译器将生成(需要时)一个pre-编译头从StdAfx.cpp文件文件,然后再利用这个pre-编译头文件标有/于所有其他文件。

And the compiler will generate (when needed) a pre-compiled header file from the StdAfx.cpp file, and then reuse this pre-compiled header file for all other files marked with /Yu.

当你创建一个新项目,旧版本的Visual C ++的(6和2003年,如果我没有记错)将默认激活precompiled头。近期的报价激活的不是他们的选择。

When you create a new project, old versions of Visual C++ (6 and 2003, if I remember correctly) would activate the precompiled headers by default. Recent ones offer the choice of activating them of not.

您应该创建一个新的VC ++项目与PCH激活启用PCH项目的工作版本,并研究编译选项。

You should create a new VC++ project with the PCH activated to have a working version of PCH-enabled project, and study the compilation options.

有关PCH更多信息,您可以访问以下网址:

For more information about PCH, you can visit the following URL:

这篇关于如何有效地使用precompiled头(使用/ YC和俞选项)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆