[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


Creating Precompiled Headers

To create a precompiled header file, you must first open a project. The settings from this project are used when precompiling. A file to be precompiled does not have to be a header file (".h" or ".hpp"), but it must meet these requirements:

To create a precompiled header file, create a text file using New Text File in the File Menu. In that text file, place your #include directives. For example, if you want to create a precompiled header file of the files string.h and stdio.h, place the following in your text file:


  #include <stdio.h>   #include <string.h>

After you save the text file, the IDE can use that text file to create a precompiled header. You can specify the name of the precompiled header at the time of precompilation. You can also specify the name by including the following line at the beginning of your text file, where name is the name you wish to call the precompiled header:


  #pragma precompile_target "name"

Windows

Append the extension ".mch" to name. This extension is required for precompiled headers.


Precompile command

To precompile a saved text file, choose Precompile from the Project Menu. This command precompiles the text file in the active window, creating a precompiled header file. If compiler errors are detected, a Message window appears.

To learn more about the Message window and correcting compiler errors, consult "Correcting Compiler Errors and Warnings."

To learn more about automatic updating of precompiled headers, see the next section, "Automatic updating."


Automatic updating

If the source code has been modified, the CodeWarrior IDE automatically updates a precompiled header during a Make or Bring Up To Date operation.

If CodeWarrior encounters a ".pch" or ".pch++" file that was modified since it was last precompiled, the IDE precompiles it again to ensure that the resulting precompiled header is up-to-date.

To create a precompiled header file that is automatically updated, open the project that uses the precompiled header. Then, create a text file that will be used to create the precompiled header.

To read about the requirements for a precompiled header text file, refer to "Creating Precompiled Headers".

In the first line of the text file, add the line:


  #pragma precompile_target "name"

This pragma tells the compiler to create a precompiled header with the file name of name.


Windows

Append the extension ".mch" to name. This extension is required for precompiled headers.

When you finish the text file, save it with a valid extension in the same folder as your project.


Windows

Save the text file with a ".pch" extension if it will be used to create a precompiled header in either C or C++.


Mac OS

Save the text file with a ".pch" extension if it will be used to create a precompiled header in C. Use the ".pch++" extension if the text file will be used to create a precompiled header in C++.

Next, choose Precompile from the Project Menu.

Now add the text file to the open project using the Add Window command in the Project Menu.

Whenever the precompiled header file is modified, the CodeWarrior project manager automatically updates the header file by precompiling it.

To include the precompiled header in a project source-code file, add this line as the first #include directive in the source-code file:


  #include "name"

Alternatively, you can specify a precompiled header as a prefix file, using the settings for your build target. To learn how to do this, refer to the discussion of the C/C++ Language settings panel in the C Compiler Guide.


NOTE

Do not use the precompiled header text file (".pch" or ".pch++") in #include directives; use the name of the resulting precompiled header file instead (".mch"). Although using the precompiled header text file is legal and does not affect the final binary, you are not taking advantage of the precompiled header's speed.

[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 17, 2000