/Yu (Use Precompiled Header File)

In this article

Instructs the compiler to use an existing precompiled header (.pch) file in the current compilation.

Syntax

/Yu[filename]

Arguments

filename
The name of a header file, which is included in the source file using an #include preprocessor directive.

Remarks

The name of the include file must be the same for both the /Yc option that creates the precompiled header and any subsequent /Yu option indicating use of the precompiled header.

For /Yc, filename specifies the point at which precompilation stops; the compiler precompiles all code though filename and names the resulting precompiled header using the base name of the include file and an extension of .pch.

The .pch file must have been created using /Yc.

The compiler treats all code occurring before the .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.

On the command line, no space is allowed between /Yu and filename.

When you specify the /Yu option without a file name, your source program must contain a #pragma hdrstop pragma that specifies the file name of the precompiled header, .pch file. In this case, the compiler will use the precompiled header (.pch file) named by /Fp (Name .Pch File). The compiler skips to the location of that pragma, restores the compiled state from the precompiled header file specified by the pragma, and then compiles only code that follows the pragma. If #pragma hdrstop does not specify a file name, the compiler looks for a file with a name derived from the base name of the source file with a .pch extension. You can also use the /Fp option to specify a different .pch file.

If you specify the /Yu option without a file name and fail to specify a hdrstop pragma, an error message is generated and the compilation is unsuccessful.

If the /Ycfilename and /Yufilename options occur on the same command line and both reference the same file name, /Ycfilename takes precedence, precompiling all code up to and including the named file. This feature simplifies the writing of makefiles.

Because .pch files contain information about the machine environment as well as memory address information about the program, you should only use a pch file on the machine where it was created.

Examples

is compiled with the command line CL /YuMYAPP.H PROG.CPP, the compiler does not process the three include statements but uses precompiled code from MYAPP.pch, thereby saving the time involved in preprocessing all three of the files (and any files they might include).

You can use the /Fp (Name .Pch File) option with the /Yu option to specify the name of the .pch file if the name is different from either the file name argument to /Yc or the base name of the source file, as in the following:

CL /YuMYAPP.H /FpMYPCH.pch PROG.CPP

This command specifies a precompiled header file named MYPCH.pch. The compiler uses its contents to restore the precompiled state of all header files up to and including MYAPP.h. The compiler then compiles the code that occurs after the MYAPP.h include statement.