Share via


The /YX (Automate Precompiled Header) Option

The /YX (Automate Precompiled Header) option instructs the compiler to use a precompiled header file with a default name of MSVC.PCH if it exists or to create one if it does not. The file is created in the current directory. You can use the /Fpfilename option to change the default name (and placement) of the precompiled header. The following command line uses /YX to create a precompiled header named MSVC.PCH:

CL /YX MYPROG.CPP

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

CL /YX /Fp\PROJPCH\MYPROG.PCH MYPROG.CPP

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 actual set of header files precompiled with /YX is determined by the compiler, which may use a subset of the header files available to make the resulting precompiled header useful in more cases.

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 filename specified with the hdrstop pragma is ignored. If any subsequent compilation using the precompiled header does not find an identical hdrstop pragma at the same point in the source file, the compiler builds a new precompiled header. For more information, see Using the hdrstop Pragma.

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 the /Yd (“duplicate debugging information in all object files”) option.