Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

/YX (Automatic Use of Precompiled Headers)

Visual Studio .NET 2003

This option instructs the compiler to use a precompiled header file (PCH) if one exists or to create one if none exists. The file is created in the current directory. You can use the /Fp option to change the default name and location of the precompiled header.

Option Description
  • Creates a file named VCx0.pch, where x is the major version of Visual C++, if it doesn't already exist, and compiles only header files into this .pch file.
  • If you have no project open, it creates a file named VCx0.pch, where x is the major version of Visual C++ in use.
  • The inclusion of .h files stops when the compiler encounters the first declaration, definition, hdrstop pragma, or #line directive in the source file being compiled with the option, or after the .h file specified in filename.
  • In subsequent compilations, the PCH is used after the compiler makes its final consistency check.
  • See Consistency Rules for /YX.
  • When creating a PCH, the compiler compiles all code up to and including the .h file specified in filename.
  • When using a PCH, the compiler treats all code occurring before the specified .h file as precompiled. It skips to just beyond the #include directive associated with the .h file, uses the code contained in the .pch file, and then compiles all code after filename.

Using the /YX option limits precompilation to header files only. The precompiled header is created when the compiler encounters the first declaration, definition, hdrstop pragma, or #line directive that occurs in the source file. In a subsequent compilation, the precompiled header is used at the point in a source file where the compiler makes its final consistency check. For more information, see Consistency Rules for /YX.

The header files precompiled by /YX are determined by the compiler, which may elect to use a subset of header files available to improve the number of cases where the resulting precompiled header can be used.

Although it is usually best to let the compiler determine which header files to use, you can selectively precompile header files by placing a hdrstop pragma in the source file between two #include directives. All header files before the hdrstop pragma are precompiled; those after are not. When used with /YX, any file name specified with the hdrstop pragma is ignored. If any subsequent compilation using the precompiled header does not contain an identical hdrstop pragma at the same point in the source file, the compiler builds a new precompiled header.

Note   If either /Yc or /Yu is specified with /YX, a warning is issued. In such cases, /YX is ignored, and /Yc or /Yu takes precedence.

Use of the /YX option implies use of the /Yd option (duplicate debugging information in all object files).

For more information on precompiled headers, see:

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
  2. Click the C/C++ folder.
  3. Click the Precompiled Headers property page.
  4. Modify the Create/Use PCH Through File property or the Create/Use Precompiled Header property.

To set this compiler option programmatically

See PrecompiledHeaderThrough Property and UsePrecompiledHeader Property.


The following command line uses /YX to create or use a precompiled header named VCx0.pch:


The following command line creates a precompiled header named MYPROG.pch and places it in the \PROJPCH directory:


See Also

Compiler Options | Setting Compiler Options

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.