CodeWarrior is a Code Development Environment that can be used in multiple platforms as an alternative to command line compilation. It can be used to produce, compile, run and debug both C and C++ applications. Because of this, it is useful for project work... it can be used to edit code at home or at work. CodeWarior has been installed in both the CEB B54 lab room and the Computer lab on the main floor of the ECERF complex. As different versions exist, this introduction will hopefully provide an introduction that can be generalized for each of the versions. It has been created as an introduction to Version 5 existing in B54.
Note: TO PRINT A FILE FROM CEB B54:
In Code Warrior, select file > print
Then click the print to file box, and name this file as a .prn file, noting the directory it is saved in.
Open the Unix terminal, Switch to the directory in which the file is saved and type the following
>lpr name_of_file.prn
To Launch CodeWarrior, the user must open a new Terminal
, and type the
command:
cwide
<press enter>
A Code
Warrior frame with the tool bar appears.
To
create a C++ project using the built-in stationary, the user must
undertake the following steps:
Select File>New Project.
The new
project panel appears, listing available stationaries.
Click
on the Triangle beside the C/C++ Stationary to view each of the
stationeries available. Select C++ Application. Select the Create
Folder checkbox if you wish to create a new folder for this
project into which all of the project's files will be saved, and
then press OK.
Suitably name the new
project in the Name new project as Dialogue box. Then press the right-uppermost
button (to the right of the padlock) and select your own directory
from the options (it should be something like
"users/eng/your_login_name" Then press SAVE.
The ".mcp" suffix is
the naming convention for project files in CodeWarrior. Using it
allows the project files to be used on any host that CodeWarrior is run on. Saving
the project creates three items:
1)
project_name.mcp (the project file itself)
2) hello.c (a
generic "hello world" source file that is always
created, and can be used as a starting point to write the program,
or can be removed)
3) project_name_Data (the project data
directory, which contains files with info about the project file,
target setting, object code, and browser
info. It should not be modified!)
To remove any file from the project by selecting it with the mouse and choosing
Project>Remove Selected Items
from
the menu bar...the file is removed from the project so that it
doesn't affect it, but the file remains on disk.
The
project window then opens, including all files contained in the current project.
To set the project type, and the name of the output file, Press the Target Settings Button:
The
Target Settings Window Opens.
From
this Select the GNU Target from the Target Settings Panels' List
on the Left hand side.
Select
the Project type you wish to create (we will be creating
applications) and enter the desired Output File Name. Press Save
and then close the window (Alt F4 or Click on the top Right Button
and Close the window).
Write the code for the
applications using the CodeWarrior Editor. From the Project Window Select
File New to Open up the Editor. To save the code as part of the
project, select
Project>Add Selected Items.
To build the Project, Press the Make button in the Project Window,
The third square button from the right. CodeWarrior then Builds
the project and creates the application. You can now run this application
by typing:
./name_of_your_output_file.out
(generically it is ./a.out)
Before you
can debug your program to solve runtime errors, you must select a Debugger. Select Project>Enable
Debugger from the Menu Bar. This will instruct CodeWarrior to
generate Debugging information the next time the project is built
for any files marked for debugging the Project Window. Now we must
select which debugger to use.
Open the Target Settings by selecting the Edit>Your_project_or_target’s_name Settings from the Menu Bar. Then Select Build Extras from the list of settings panels on the left-hand side of the window. The Build Extras settings panel is now displayed.
Click
the Use third party debugger checkbox to select it, and type the
following command into the edit field beneath:
xterm
-e gdb %1
(this selects gdb to debug in a new terminal and the %1 is automatically replaced by CodeWarrior to with the name of the application.)
Click
the save button, at the bottom right-hand corner of the Target
Settings Window, and Close the window.
Recompile the
project and Run the application by Pressing the run button in the
project Window, The Second button from the Right had side.
The gdb debugger will open
in a new x terminal awaiting a command. Type
run
<press
enter>
The
debugger will run through the program and determine if there are
any runtime errors. To
turn the debugging off, Select Project>Disable Debugger.
Then choose Project>Make to build the Final
Application!
Note: Code Warrior removes the need for
makefiles, which are files used to instruct the gnu compiler and
linker on how to correctly build the executable program by using
the project files (.mcp).