Using a Precompiled Header File

Although a precompiled file is not a text file, you use it like you would a regular header file. To include a precompiled header file in a source code file, use the #include directive.

Note: Unlike regular header files in text format, a source code file may include only one precompiled file.
Tip: Instead of explicitly including a precompiled file in each source code file with the #include directive, put the #include directive in the Prefix Text field of the C/C++ Preprocessor settings panel and make sure that the Use prefix in precompiled headers option is on. If the Prefix File field already specifies a file name, include the precompiled file in the prefix file with the #include directive.

The following listing shows an example.

Listing: Header File that Creates a Precompiled Header File for C
// sock_header.pch

// When compiled or precompiled, this file will generate a 

// precompiled file named "sock_precomp.mch"

#pragma precompile_target "sock_precomp.mch"

#define SOCK_VERSION "SockSorter 2.0"

#include "sock_std.h"

#include "sock_string.h"

#include "sock_sorter.h"

The following listing shows another example.

Listing: Using a Precompiled File
// sock_main.c

// Instead of including all the files included in 

// sock_header.pch, we use sock_precomp.h instead.

//

// A precompiled file must be included before anything else.

#include "sock_precomp.mch"

int main(void)

{

  // ...

  return 0;

}