This chapter discusses how to compile and link a project to produce a final executable file, and how to correct common compiler and linker errors using the Message window. 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 these tasks, refer to other chapters in this book, including "Working with Projects" on page 41, "Working with Files" on page 107, "Editing Source Code" on page 133, and "Configuring IDE Options" on page 249.
You should also be familiar with the columns and pop-up menus in the Project window. To learn more about these features, refer to "Working with Projects" on page 41.
This chapter does not describe in detail the various types of programs the CodeWarrior IDE can create. For that information, please see the Targeting manual appropriate for your platform. A table describing some of these manuals is shown in "Targeting Manuals for various platform targets" on page 28.
The topics in this chapter are:
To associate a plug-in compiler with a given file, you must configure the options in the File Mappings settings panel. For a description of how to configure these options to assign a compiler to your source code files, refer to "File Mappings" on page 334.
All compiling and linking commands are available from the Project Menu. Depending on your project type, some of these commands might be disabled or have different names. For example, you cannot Run a shared library, but you can Make it. Also, a command for compiling or linking might be dimmed because CodeWarrior is busy executing another command, or the project is being debugged.
If you have multiple projects open at the same time, you might want to learn about selecting a default project before compiling and linking. For more information, refer to "Choosing a Default Project" on page 73.
The topics in this section are:
You might want to switch between multiple build targets in a project when compiling files. To learn more, refer to "Setting the Current Build Target" on page 96.
The Compile command in the Project Menu is grayed out in the following situations:
To compile a single file in your project, select that file in the Project window and choose Compile from the Project Menu.
Alternatively, you can open the file in the CodeWarrior editor, make the editor window the active window, and choose Compile from the Project Menu.
You can compile several files in your project by selecting those 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" on page 76.
CodeWarrior does not always recognize file changes and might not automatically recompile the file. You can force CodeWarrior to recompile a changed file by "touching" that file. To learn how to touch a file, refer to "Touching and Untouching Files" on page 89.
After touching the file or files that you want to recompile, choose Bring Up To Date or Make from the Project Menu.
You can specify the order in which the IDE compiles files by using the Link Order View of the Project window. By re-arranging the order of the files, you can prevent linkage errors caused by file dependencies. In other words, if file Aleph
depends on the completed compilation of file Zeta
, you can use change the link order and position file Zeta
to compile before file Aleph
, thus preventing an error message.
To set the link order in the current project:
1. Click the Link Order tab in the Project window.
The Link Order view appears in the Project window.
2. Sort the files into the desired link order.
Drag and drop each file into the desired build order.
The next time you Bring Up To Date, Make, Run, or Debug the project, the IDE uses the new build order.
See "Link Order View" on page 51 for additional information.
When you have many newly-added, modified, or touched files in your project, you can use the Bring Up To Date command in the Project Menu to compile all of the files.
When using this command, the linker is not invoked, so the compilation does not produce an output binary of your project. The Bring Up To Date command only runs the compiler.
You might want to switch between multiple build targets when updating a project. To learn how to do this, refer to "Setting the Current Build Target" on page 96.
When you are ready to produce a binary file, such as an application, library, or shared library, use the Make command in the Project Menu. This command builds the selected project type by updating the newly-added, modified, and touched files, and then linking the project into a final executable file.
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 that application in the same folder as your project. Table 10.1 lists some sample project types and the resulting files after issuing a Make command. To find a full list of the types of software products you can produce, refer to the Targeting manual for your build target. Refer to Table 1.1 on page 28 to determine which manual applies to various build targets.
Project Type
|
Build Target
|
Make Command Creates
|
---|---|---|
Once all the modified files and touched files have been compiled successfully, CodeWarrior links all the files in 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.
You might want to switch between multiple build targets in a project when making that project. Refer to "Setting the Current Build Target" on page 96 for more information.
When you choose Enable Debugger command from the Project Menu, the Debug command runs the CodeWarrior debugger in order to debug your project. When you choose Disable Debugger from the Project Menu, the Run command runs your project normally.
To learn how to generate debugging information for all of the files in the project, refer to "Controlling Debugging in a Project" on page 103.
To learn more about running your project, refer to the following section, entitled "Running a Project."
When you choose the Run command from the Project Menu, CodeWarrior compiles and links the project (if necessary), creates a stand-alone application, and then launches that application.
When compiling and linking is successful, CodeWarrior saves the new application to your hard disk. The new application is named according to options you set in the Target Settings window. If you would like to change these options, refer to "Choosing Target Settings" on page 318.
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" on page 361.
The second step is for you to launch the debugger with your compiled application as the debug target. You can do this by choosing the Debug command from the Project Menu. If the Debug command is not visible in the menu, your project is not currently configured for debugging. Refer to "Enabling Debugging" on page 361 to learn how to remedy this problem.
If the Debug command is grayed out, make sure to configure the proper options for debugging, as detailed in "Enabling Debugging" on page 361. If the Debug command is still grayed out, you are probably attempting to run a project whose project type cannot be run (such as a shared library or dynamic link library), or the application is already running.
The settings to control this option are in the build target's Linker panels. After configuring these panels as desired, you must Make your project. If the compile and link operations are successful, the IDE generates a link-map file, names the file after your project, adds a .MAP
extension, and saves the link-map file in your project folder.
If you want to update the modification dates of all the files stored in the project, choose the Synchronize Modification Dates command from the Project Menu.
To learn more about this topic, see "Synchronizing modification dates" on page 90.
In some cases, you might wish to remove all of the object code from the project and restart the compiling and linking process. To remove a project's object code, select the Remove Object Code command from the Project Menu. The dialog box shown in Figure 10.2 appears.
To learn how to change the current build target of your project, refer to "Setting the Current Build Target" on page 96.
This command removes all binaries from the project and compacts the project to consume the minimum amount of space on your hard disk. The procedure is similar to that discussed in "Removing Object Code" on page 364, but in addition the project file is compressed.
For more information about this command, refer to "Remove Object Code & Compact" on page 615.
You can start a project compile/link cycle in CodeWarrior, then switch to another application running on your machine. To learn how to receive notification when CodeWarrior completes the build process, refer to "Play sound after `Bring Up To Date' & `Make' (Mac OS)" on page 253.
To learn how to optimize the speed of your builds in CodeWarrior, refer to "Use modification date caching" on page 331.
To shorten the time spent compiling and recompiling a header file, use the Precompile command in 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:
.pch
" or ".pch++
," at the end of its file name.
const
).
#include
directive.
#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>
#pragma precompile_target "name"
Append the extension ".mch
" to name. This extension is required for precompiled headers.
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" on page 379.
To learn more about automatic updating of precompiled headers, see the next section, "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.
To read about the requirements for a precompiled header text file, refer to "Creating Precompiled Headers" on page 366.
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.
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.
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.
#include "name"
.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.
Open your project and create a new text file with the New Text File command on the File Menu.
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.
For example, if the prefix file is MyHeaders
, then the first directive in the text-file window is:
#include <MyHeaders>
#pragma precompile_target "MyPrecomp"
5. Type in all your own preprocessor directives.
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.
Save the text file with a ".pch
" extension.
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.
In this example, you would enter "MyPrecomp.mch
" in the Prefix File field.
Open your project and create a new text file with the New Text File command.
This new text file will contain your compiler directives.
2. Open the Pascal 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 Pascal 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.
For example, if the prefix file is OtherDefs.p
, then the first directive in the editor window is:
{$I OtherDefs.p}
4. Type in all your own {$SETC}, {$I}, and other preprocessor directives.
The text file cannot contain any source code that generates data or executable code.
5. Save
the text file.
6. Precompile the text file.
Choose Precompile from the Project Menu. The IDE uses the text file to create a precompiled header file.
7. Open the Pascal Compiler settings panel.
Choose Target Settings from the Edit Menu, and select the Pascal Language settings panel.
Open a file that you want to preprocess, or select a file in your currently-open Project window. To preprocess a file, select the Preprocess command from the Project Menu. The results of the Preprocess command are stored in a new file. This new file is named after the preprocessed source-code file and begins with the "#" character.
To save the contents of the new window, choose one of the save commands in the File Menu.
The Disassemble command in 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."
To save the contents of the ".dump" window, choose one of the save commands in the File Menu.If the file being disassembled has not been compiled, choosing the Disassemble
command causes the IDE to compile the file before disassembling it.
The Message window, shown in Figure 10.3, is used to display messages about events that have occurred when compiling, linking, or searching files. There are a number of elements in the window that are useful for accomplishing certain tasks, such as navigating to error locations and scrolling to see all messages for a project.
There are some user interface items in the Message window that are not discussed here. To learn about the Marker Pop-Up Menu, Options Pop-Up Menu, VCS Pop-Up Menu, File Path Caption and Line Number Button, refer to "Guided Tour of the Editor Window" on page 133.
The topics in this section include:
To learn more about seeing error messages in the Message window, refer to "Seeing Errors and Warnings" on page 377.
The Warning Button in the Message window 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" on page 377.
The Stepping Buttons allow you to step up or down through the messages in the window.
To learn more about stepping through messages in the Message window, refer to "Stepping Through Messages" on page 378.
The Message List Pane displays your messages.
To learn more about seeing messages in the Message window, refer to "Seeing Errors and Warnings" on page 377.
The Source Code Disclosure Triangle allows you to hide the Source Code Pane of the Message window.
The Source Code Pane of the Message window allows you to view the source code at the location referred to by a message. To learn more about the view in this window, refer to "Seeing Errors and Warnings" on page 377.
While compiling your project, the CodeWarrior IDE may detect a syntax error or other type of compiler error in one of your project's source code files. If this happens, the Message window displays the total number of errors and warnings, and information about each one. See "Guided Tour of the Message Window" on page 373 for information on the interface items in this window.
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 Errors & Warnings Window command from the Window Menu to reopen it.
To see only error messages in the Message List Pane, click on the Error Button and turn off the Warning Button.
To see only warnings in the Message List Pane, click the Warning Button and turn off the Error Button.
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:
Find Reference
when more than one definition for the same function is found (multiple definitions).
Find Reference
on a C++ function that has been overridden, the Message window appears with a warning that there are two or more instances.
When the compiler finds errors during a build, or the CodeWarrior IDE search command finds text you asked it to look for when Using Batch Searches, you will see the message window.
The window is divided into two panes:
To step through the list of messages, click the up or down Stepping Buttons or click the error message you are interested in.
To navigate the source code that is shown in the Source Code Pane for a given message, you use the Interface Pop-Up Menu, Routine Pop-Up Menu, or the Line Number Button. To learn about how to use these navigational features, refer to "Guided Tour of the Editor Window" on page 133.
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 be shown in the Source Code Pane. You can navigate to the spot in your source code where the message refers to, and inspect or correct your code.
To correct a compiler error or warning, you must first find the cause. First, make sure that the Source Code Pane of the Message window is visible. If it isn't visible, refer to "Source Code Disclosure Triangle" on page 376 to learn how to make it visible.
To view the statement that the compiler believes has caused the error or warning, select the message in the Message List Pane of the Message window. Notice that the Source Code Pane view now shows the source code that corresponds to the message. A statement arrow points to the line of code that the compiler reports as an error. The statement arrow is shown in Figure 10.4. Using the statement arrow as a guide, you can then edit the erroneous line directly in the Source Code Pane view.
Use the Interface Pop-Up Menu, Routine Pop-Up Menu, or the Line Number Button in the Source Code Pane to navigate your code or open interface files. To learn about how to use these navigational features, refer to "Guided Tour of the Editor Window" on page 133.
To open a source code file that corresponds to a given message, select the message in the Message List Pane and press Enter/Return. You may also double-click the message in the Message List Pane to open the relevant file.
When your project is linked, any errors that may occur can be viewed and corrected.
If the linker encounters any errors while linking your project, the Message window appears indicating these errors. This window can be scrolled through by using the scroll bar or Stepping Buttons.
To learn about how to scroll through messages in the Message window, refer to "Stepping Buttons" on page 375. To learn about changing the view of messages in the Message window, refer to "Seeing Errors and Warnings" on page 377.
Linker errors are usually the result of one of the following circumstances:
To find out which libraries or shared libraries should be added to your project, you can refer to the CodeWarrior Targeting manual appropriate for your target, as described in Table 1.1 on page 28. In addition, you can use the Find Library tool included on the CodeWarrior Tools CD.
Here's how to use the Find Library tool.
Use the Find window to create a set that includes all the files in the Find Library
folder on your CodeWarrior Tools CD. To learn how to create and use a file set, refer to "Choosing Files to be Searched" on page 187 and "Saving a File Set" on page 191.
2. Set the search parameters to ignore case.
3. Search for the symbol that the linker can't find.
The CodeWarrior Pascal compiler's Make and Run commands build your project by examining every Pascal file in your project file. As this examination is performed, a tree of dependencies is built for the interfaces of your units and for their implementations.
The example in Listing 10.1 is perfectly valid, since both A's and B's interfaces depend on C's, but are independent from one another. Knowing everything that was declared, A's implementation depends on all interfaces, the same is true for B's and C's. For this example, the make utility will ask the compiler to compile Listing 10.1 in the following order:
UNIT A; UNIT B; UNIT C;
INTERFACE INTERFACE INTERFACE
USES C; USES C;
TYPE TYPE TYPE
A_type = ... B_type = .... C_type = ...
IMPLEMENTATION IMPLEMENTATION IMPLEMENTATION
USES B; USES A; USES A, B;
.... ... ...
3. All of unit A is compiled (unit and implementation),
4. B's implementation is compiled.
5. C's implementation is compiled.
To print or save the contents of the Message window, just follow these steps.
1. Make the Message window active.
To accomplish this, either click on the deactivated Message window, or select the Errors & Warnings Window command from the Window Menu.
2. Select the Print command from the File Menu.
If you choose the Print command on the File Menu to print the Message window, the print dialog box appears. Specify printing options and click OK. All the errors, warnings, and messages will be printed.
To learn more about printing, refer to the documentation that came with your printer.
1. Make the Message window active.
To accomplish this, either click on the deactivated Message window, or select the Errors & Warnings Window command from the Window Menu.
2. Select the Save A Copy As command from the File Menu.
The Save A Copy As command will display a standard file dialog box.
3. Specify the name of the file and the location.
There are a few special linker options you can use in your project. These options are only accessible from the Project Inspector window as shown in Figure 10.5, available from the Window Menu. These options are only available for library files in the project, and are disabled for text files in the project.
The topics in this section are: