Share via


Creating Precompiled Header Files

The Microsoft C and C++ compilers provide options for precompiling any C or C++ code—including inline code. Using this performance feature, you can compile a stable body of code, store the compiled state of the code in a file, and during subsequent compilations combine the precompiled code with code that is still under development. Each subsequent compilation is faster because the stable code does not need to be recompiled.

Visual C++ offers two ways to create and use precompiled header files:

  • Use AppWizard and allow it to set default compiler options for your application.

  • Set compiler options yourself, either on the command line or in the development environment (Project menu, Settings command).

With Microsoft Visual C++, you can precompile any C or C++ code; you are not limited to precompiling only header files. To precompile headers, you can choose one of two approaches:

  • Automatic precompiling: Use just one option (/YX) and let the compiler decide when to create and use precompiled headers.

  • Manual precompiling: Use this when you know that your source files use common sets of header files but do not include them in the same order, or when you want to include source code in your precompilation.

The first choice is quick and easy. The second requires some planning, but it offers significantly faster compilations if you precompile source code other than simple header files.

What do you want to know more about?