|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
/Yc (Create Precompiled Header File)
Instructs the compiler to create a precompiled header (.pch) file that represents the state of compilation at a certain point.
When /Yc is specified without an argument, the compiler compiles all code up to the end of the base source file, or to the point in the base file where aoccurs. The resulting .pch file has the same base name as your base source file unless you specify a different file name using the hdrstop pragma or the /Fp option.
The precompiled code is saved in a file with a name created from the base name of the file specified with the /Yc option and a .pch extension. You can also use theoption to specify a name for the precompiled header file.
If you use /Ycfilename, the compiler compiles all code up to and including the specified file for subsequent use with the /Yu option.
If the options /Ycfilename and filename occur on the same command line and both reference, or imply, the same file name, /Ycfilename takes precedence. This feature simplifies the writing of makefiles.
For more information on precompiled headers, see:
To set this compiler option in the Visual Studio development environment
Select a .cpp file. The .cpp file must #include the .h file that contains precompiled header information. The project's /Yc setting can be overridden at the file level.
Open the project's Property Pages dialog box. For details, see.
Click the C/C++ folder.
Click the Precompiled Headers property page.
Modify the Create/Use PCH Through File property or the Create/Use Precompiled Header property.
To set this compiler option programmatically
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 app ...
When this code is compiled with the command CL /YcMYAPP.H PROG.CPP, the compiler saves all the preprocessing for AFXWIN.h, RESOURCE.h, and MYAPP.h in a precompiled header file called MYAPP.pch.