Skip to content

Latest commit

 

History

History
74 lines (47 loc) · 3.76 KB

yc-create-precompiled-header-file.md

File metadata and controls

74 lines (47 loc) · 3.76 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: /Yc (Create Precompiled Header File)
/Yc (Create Precompiled Header File)
11/04/2016
VC.Project.VCCLCompilerTool.UsePrecompiledHeader
/yc
VC.Project.VCCLWCECompilerTool.PrecompiledHeaderThrough
VC.Project.VCCLWCECompilerTool.UsePrecompiledHeader
VC.Project.VCCLCompilerTool.PrecompiledHeaderThrough
precompiled header files, creating
PCH files, creating
.pch files, creating
-Yc compiler option [C++]
/Yc compiler option [C++]
Yc compiler option [C++]
47c2e555-b4f5-46e6-906e-ab5cf21f0678

/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.

Syntax

/Yc
/Ycfilename

Arguments

filename
Specifies a header (.h) file. When this argument is used, the compiler compiles all code up to and including the .h file.

Remarks

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 a hdrstop directive occurs. 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 the /Fp (Name .Pch File) option 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 (Use Precompiled Header File) option.

If the options /Ycfilename and /Yufilename 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

  1. 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.

  2. Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.

  3. Open the Configuration Properties, C/C++, Precompiled Headers property page.

  4. Modify the Precompiled Header property.

  5. To set the filename, modify the Precompiled Header File property.

To set this compiler option programmatically

  • See xref:Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool.PrecompiledHeaderThrough%2A and xref:Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool.UsePrecompiledHeader%2A.

Example

Consider the following code:

// prog.cpp
// compile with: cl /c /Ycmyapp.h prog.cpp
#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.

See also

MSVC Compiler Options
MSVC Compiler Command-Line Syntax
Precompiled Header Files