Use Precompiled Header Option (/Yu)

The “use precompiled header” option (/Yu) instructs the compiler to restore its state from a precompilation using a precompiled header file. The syntax of this option is:

/Yu[[filename]]

Using /Yu with a Filename

If a filename is specified, it must correspond to one of the header files included in the source file using an #include preprocessor directive. The compiler skips to the specified #include directive, then restores its state from the precompiled header file.

The precompiled header file has the same base name as the specified include file, and a .PCH extension. Consider the following code:

#include <afxwin.h> // Include header for class library

#include "resource.h" // Include resource definitions

#include "myapp.h" // Include information specific to this

// application

...

When compiled with the command line

CL /YuMYAPP.H PROG.CPP

the compiler does not process the three #include statements, but restores its state from the precompiled header MYAPP.PCH, thereby saving the time involved in preprocessing all three of the files (and any files they might include).

Using /Yu Without a Filename

When you specify the /Yu option without a filename, your source program must contain a hdrstop pragma. The compiler skips to the location of that pragma and restores the state of the compiler from the precompiled header file specified in that pragma. If the hdrstop pragma does not specify a filename, the name is derived from the base name of the source file, with the .PCH extension. You can also use the /Fp option to specify a different .PCH file.

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