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


Defining Symbols For C/C++

To automatically update and add predefined symbols and other preprocessor directives, you can create a precompiled header file, add it to your project, and include it in the prefix file specified in the C/C++ Language settings panel.

1. Create a new text file.

Open your project and create a new text file with the New Text File command on the File Menu.

This new text file will contain your preprocessor directives. You will use this file as a precompiled header file that you will add to your project.

2. Open the C/C++ Compiler settings panel.

Choose Target Settings from the Edit Menu. The actual name of the Target Settings command includes the name of the current build target. Select the C/C++ Language settings panel in the Target Settings window.

3. Get the Prefix File name if it exists.

If there is a file name in the Prefix File field, Copy it, then close the Target Settings window.

In the new text file window, paste the file name that you copied from the Prefix File field into an #include directive. Make sure this is the first directive in the text file.

For example, if the prefix file is MyHeaders, then the first directive in the text-file window is:


  #include <MyHeaders>

4. Add the #pragma statement.

Add the #pragma precompile_target statement to the text file. This statement lets you name the precompiled file. For example, to create a file named MyPrecomp, use the following statement:


  #pragma precompile_target "MyPrecomp"

Windows

Append the extension ".mch" to the desired file name. This extension is required for precompiled headers. In this example, "MyPrecomp.mch" is the correct file name.

5. Type in all your own preprocessor directives.

Type in all your own #define, #include, and other preprocessor directives corresponding to the needs of your source code. The text file cannot contain any source code that generates data or executable code. However, C++ source code can contain inline functions and constant variable declarations (const).

6. Save the text file.

Choose Add Window from the Project Menu to add the text file to your project. Save the text file with a valid extension in the same folder as your project.


Windows

Save the text file with a ".pch" extension.


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++.

7. Precompile the text file.

Choose Precompile from the Project Menu. The IDE uses the text file to create a precompiled header file.

8. Open the C/C++ Compiler settings panel.

Choose Target Settings from the Edit Menu and select the C/C++ Language settings panel.

9. Set the new Prefix File.

In the Prefix File field, enter the name of your precompiled file, or "MyPrecomp" in this example. Click Save to save your changes.


Windows

In this example, you would enter "MyPrecomp.mch" in the Prefix File field.

Whenever CodeWarrior builds your project, the project manager updates your precompiled header and automatically includes it in each source code file.


[ 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