This chapter discusses how to control compilation, linking and running a CodeWarrior project.
The information in this chapter assumes you have already created a project, added the necessary files, grouped these files, and set the project's options. To learn more about how to do these things, refer to other chapters in this book, including "Projects Overview," "Working with Files Overview," "Source Code Editor Overview," and "Configuring IDE Options Overview."
You should also be familiar with features such as moving files in the project window, the project window's columns, and pop-up windows. To learn more about how to do these things, refer to "Projects Overview,"
This chapter discusses how to compile and link a project to produce your code, and how to correct common compiler and linker errors using the Message window. It does not describe in detail the various types of programs CodeWarrior can create. For that information, please see the CodeWarrior Targeting manual appropriate for your platform. A table describing which guide to refer to is shown in "Where to Go From Here."
The topics in this chapter are:
To associate a plugin compiler with a given file, you set the Target options. For a description of how to configure these options to set a compiler for your source code files, refer to "Target."
The Compile command on the Project Menu is dimmed when:
To compile a single file in your project, select that file in your Project window and choose Compile from the Project Menu. To learn how to select several files in your project, refer to "Selecting Files and Groups."
Alternatively, you can open the file in the CodeWarrior Editor, make the window the active window, and choose Compile from the Project Menu.
You may select numerous files in your project for compilation, by selecting the files in the Project window and then choosing Compile from the Project Menu. To learn how to select several files in your project, refer to "Selecting Files and Groups."
When you have many newly added or modified files in your project, you can use the Bring Up To Date command on the Project Menu to compile all the files that need recompiling. The Project window message area displays information on the compilation process, as shown in Figure 8.1.
When you are ready to produce your binary file, such as an application, library, or shared library, you use the Make command on the Project Menu. This command builds the selected project type by updating the newly added or modified files, then linking the project, copying resource files, and executing any postlink source files.
The results of a successful build depend on the selected project type. For example, if the project type is an application, the Make command builds an application and saves it in the same folder as your project. Table 8.1 lists each project type and what is built when the Make command is executed.
Project Type
|
Target
|
Make Creates
|
---|---|---|
Once all the modified files have been compiled successfully, CodeWarrior links the project to produce your output binary. If the project has already been compiled using Bring Up To Date or another command, then the Make command only links the compiled source code files together.
When the Enable Debugger option is checked in the Project Menu, choosing the Debug command lets the CodeWarrior Debugger launch and debug your project. When you choose Disable Debugger from the Project Menu, choosing the Run command runs your project normally.
To learn about how to configure your project so that files in the project have debugging information generated for them, refer to "Controlling Debugging in a Project."
To learn more about running your project, refer to "Running a Project."
When you choose the Run command from the Project Menu, CodeWarrior compiles and links (if necessary), and creates a stand-alone application, then launches that application.
When compiling and linking is successful, CodeWarrior saves a new application in the same folder as the open project. It is named according to options you set. If you would like to change these options, refer to "Project Settings Panels."
If the current project is for a library, shared library,or plugin, the Run command is not available.
To debug your project, there are basically two steps you need to do. Of course, you must already have your project compiled and linked with debugging information generated. To learn how to enable debugging for your project, refer to "Enabling Debugging."
The second step is for you to start the debugger with your compiled application as the debug target. You can do this by selecting the Debug command from the Project Menu. If the Debug command is not in the menu, you do not have debugging enabled for your project. Refer to "Enabling Debugging" to learn how to remedy this.
If the Debug command is dimmed, make sure the proper options for debugging are configured, as detailed in "Enabling Debugging". Also, make sure that Metrowerks Debugger application is on your hard disk. If Debug is still dimmed, you are probably attempting to run a project whose project type cannot be run, such as a shared library or library.
In some cases, you may wish to remove all the object code from the project and restart the compiling and linking process. To remove a project's binaries, select the Remove Objects command from the Project Menu.
When Remove Objects is chosen, it resets the Code and Data size of each file in the project window to zero.
When the Option key is held down, choosing Remove Objects removes all binaries from the project and compacts it to consume the minimum amount of space on your hard disk.
To shorten the time spent compiling and recompiling a header file, use Precompile on the Project Menu. A precompiled header file takes the compiler significantly less time to process than an ordinary, uncompiled header file.
The topics in this section are:
const
).
#include
directive.
To precompile a file, choose Precompile from the Project Menu. The progress of this operation is displayed in the Project window message area. 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."
During a Make or Bring Up To Date operation, CodeWarrior automatically updates a precompiled header file if its source has been modified.
To read about the requirements for a precompiled header source file, refer to "Creating Precompiled Headers".
Save the source file with a .pch or .pch++ filename extension.
Now add the source file to the open project with the The Project Menu lets you add and remove files and libraries from your project. It also lets you compile, build, and link your project. All of these commands are covered in this section.
#include "name"
Alternatively, you may also specify the use of a precompiled header file in your project settings. To learn about how to do this, refer to "C/C++ Language."
.pch
or .pch++
source file in #include
directives; use the name of the resulting precompiled header file. Although using the .pch
or .pch++
file is legal and will not affect the final binary, you won't be taking advantage of the precompiled header's speed.
First, open your project and create a new source code file with the New Text command on the File Menu.
Choose Settings from the Window Menu, and select the C/C++ Language.
For example, if the Prefix file is MyHeaders, then the first directive in the editor window is
Type in all your own #define
, #include
, and other preprocessor directives.
Save this file with a .pch
or .pch++
filename extension.
Choose Project Menu from the Project Menu to add this precompiled header source file to your project.
Choose Settings from the Window Menu, and select the C/C++ Language.
For example, Figure 8.3 shows a source code file before using the Preprocess command on the Project Menu.
Open a file that you want to preprocess, or select a file in your currently-open Project window. To preprocess afile, select the Preprocess command on the Project Menu. The results of the Preprocess command are stored in a new file named after the source code file that was preprocessed and beginning with the "#" character (Figure 8.4).
To save the contents of the new window, choose one of the save commands in the File Menu.
There are two ways to disassemble a source code file using the CodeWarrior IDE:
The Disassemble command on the Project Menu disassembles the compiled source code file selected in the project window and displays its assembly-language code in a new window. The title of the new window consists of the name of the source code file with the extension ".dump" (Figure 8.5).
To save the contents of the ".dump" window, choose one of the save commands in the File Menu.
For further information on the Machine Code option, see "Machine Code Listing."
The topics in this section include:
The Error check box in the Message window, shown in Figure 8.6, toggles the view of error messages on and off. This is useful if you have changed the view of the window to something else and want to get back to viewing the error messages.
To learn more about seeing error messages in the Message window, refer to "Seeing Errors and Warnings."
The Warning check box in the Message window, shown in Figure 8.6, toggles the view of warning messages on and off
To learn more about seeing error messages in the Message window, refer to "Seeing Errors and Warnings."
The Notes check box in the Message window, shown in Figure 8.6, toggles the view of note messages on and off
To learn more about seeing note messages in the Message window, refer to "Seeing Errors and Warnings."
The Message List Pane, shown in Figure 8.6, allows you to view your messages.
To learn more about seeing messages in the Message window, refer to "Seeing Errors and Warnings."
The Message window displays several types of messages:
Select this
|
To display this
| |
---|---|---|
To close the Message window, click its close box or select Close in the File Menu while the Message window is the active window. If you close the message window and want to see it again, choose the Message Window command from the Window Menu to reopen it.
To see only error messages in the Message List Pane, click on the Error Check Box and turn off the Warning Check Box.
To see only warnings in the Message List Pane, click the Warning Check Box and turn off the Error Check Box.
To see both errors and warnings in the Message List Pane, click both buttons. Notes do not appear in the Errors & Warnings window.
You'll also see other types of messages from time to time in a Message window, such as:
When the compiler finds errors during a build, or the CodeWarrior search engine finds text you asked it to look for when Using Batch Searches, you'll see the message window.
When an error occurs during compilation, the Message window will show you the error message in the "Message List Pane". The location in the source code that the message refers to will allow you to navigate to the spot in your source code where the message refers to, and inspect or correct your code. You can do this easily by selecting the message in the Message List Pane and then hitting the Enter key.
For a complete list of compiler errors and their possible causes, consult CW Error Reference.
To open a source code file that corresponds to a given message, select the message in the "Message List Pane" and press Enter. You may also double-click the message in the "Message List Pane" to open the relevant file.
If the linker encounters any errors while linking your project, the Message window appears indicating these errors (Figure 8.9). This window can be scrolled through using the scroll bar or arrow keys.
To learn about how to scroll through messages in the Message window, refer to "Using the Message Window." To learn about changing the view of messages in the Message window, refer to "Seeing Errors and Warnings."
Linker errors are usually the result of one of the following circumstances:
To save the contents of the Message window, just follow these steps.
First, make the message window active. To accomplish this, either click on the deactivated message window, or select "Message Window" from the Window Menu.
Next, select the "Open File" command from the File Menu.
The "Save A Copy As" command will display the following dialog (Figure 8.10)
These steps explain how to run a shell script from the IDE:
cp MyApplication MyApplication.xMAP /boot/Apps/
/bin/beep
Type a shell script for your project, and save it to your hard drive as samplescript.sh
.sh
as a standard naming convention for shell scripts.
2. Add this script to your project.
Drag the script file to one of your groups in the project window.
3. Make sure the IDE recognizes the script.
a. Tell the IDE the extension of the file you want it to recognize.
In the Extension edit field, type the extension "sh"
, without the quotes.
b. Tell the IDE which tool to use with this extension.
Click the Tool Name pop-up menu, and choose sh
as the tool to use with this extension.
c. Tell the IDE when it should execute this script.
Choose Make
from the Project
menu to compile your project and run the script.