Using Precompiled Headers with Clang-based C++ Compilers
Go Up to Clang-based C++ Compilers
A precompiled header file is a C++ header file that is precompiled so that it is processed faster at compilation time. A precompiled header is a C++ header file in this intermediate form. When you use a Clang-based C++ compiler, your projects can only use one precompiled header for precompiling at a time. (When you use BCC32, your projects can use multiple precompiled headers each.)
PCH.h File is the Default Precompiled Header File for C++ Applications
One precompiled header is automatically generated for every C++ project. The default name for the generated precompiled header file is:
- <projectname> is the name of the project for which the precompiled header is created.
- <n> is the number of the precompiled header.
For example, when you create a new C++ application named Project1, the following precompiled header is automatically generated, regardless of the compiler used to build this project:
The PCH.h file is a node in the Project Manager for every C++ project. The automatically generated precompiled header (the PCH.h file) is used by default in compiling C++ 64-bit Windows applications.
Using BCC32: The 32-bit Windows C++ compiler has always had the default behavior of generating precompiled headers for you, and this behavior is not changed. Now, however, you can tell BCC32 to use the PCH.h file shown in the Project Manager if you simply
#includethe PCH.h file (followed by
#pragma hdrstop;) in each source file in your project. You should, of course, edit the contents of the PCH.h file to
#includeall the headers needed in your project.
Creating a Precompiled Header for Clang-based C++ Compilers
The following procedure shows how to use precompiled headers for Clang-based C++ compilers. These compilers accept only one header file per project. Following the steps below, you create the single header file and use it as a precompiled header for a source file.
- Create a C++ application ( either Console Application, VCL or FireMonkey).
- You can use either a brand new application or an application that you created in a version of Appmethod C++ prior to XE3; that is, you could have made changes and additions to the application since it was created or it could be a legacy application created in an earlier version of Appmethod C++).
- Select File > Save All. Save all the files of the project to a desired location.
- In the Project Manager, enable the target platform that uses a Clang-based C++ compiler (such as 64-bit Windows) and the PCH file:
- Right-click Target Platforms, select Add Platform and select the target platform.
- Right-click your project's PCH.h file and make sure that Use for precompiling is enabled.
- Edit the header file (PCH.h) file, and include the header files that you want to precompile. The PCH.h file should end with:
- Save the PCH.h file in the project folder.
- In the Project Manager, right-click the source file that you want to include the PCH.h precompiled header, and select Edit local options from the context menu.
- Press F9 to run the project.
Here is the BCC64 command line for the source file for which the precompiled header is set. Note the command line option that includes a precompiled header into a source file (