Share via


Using the hdrstop Pragma

The hdrstop pragma gives you additional control over precompilation filenames and over the place at which the compilation state is saved. The syntax of the hdrstop pragma is

#pragma hdrstop ("filename")

where filename is the name of the precompiled header file to use or create (depending on whether /Yu or /Yc is specified). If the filename does not contain a path specification, the precompiled header file is assumed to be in the current directory. Any filename is ignored when the automatic precompiled header option (/YX) is specified.

Note   The hdrstop pragma is ignored unless either the /YX option is specified or the /Yu or /Yc compiler option is specified without a filename.

For the /Yc and /Yu options, if neither of the two compilation options nor the hdrstop pragma specifies a filename, the base name of the source file is used as the base name of the precompiled header file. This differs from the precompiled-header naming conventions of /YX; with /YX, the default name of the precompiled header is MSVC.PCH.

The filename specified in the hdrstop pragma is a string and is therefore subject to the constraints of any C or C++ string. In particular, you must escape backslashes ( \ ) when specifying paths. For example:

#pragma hdrstop( "d:\\include\\myinc.pch" )

You can also use preprocessing commands to perform macro replacement as follows:

#define INCLUDE_PATH "c:\\progra~`1\\devstsu~1\\vc\\include\\"
#define PCH_FNAME "PROG.PCH"
.
.
.
#pragma hdrstop( INCLUDE_PATH PCH_FNAME )

See Placement of the hdrstop Pragma for more guidelines.