Using Projects with Metworks Codewarrior
Introduction
This information will apply to many versions of Codewarrior,
but it has been tested only with version 9 (IDE 1.6), 10 (IDE 1.7),
and version 12 (IDE 2.0). In particular, it has not been tested
with version 11,
and many people have reported problems with version 11,
including Metwrowerks! Advice: don't use version 11.
When using Codewarrior you MUST use a
project, but by creating
project stationary you can make it
possible for students to have all the AP classes (and others you want to
use) included in a default project automatically.
When creating a new project, you must take care to specify the project
type properly. You must also set certain preferences using the
EDIT menu choosing the
PREFERENCES...special AP
project stationary you'll make it possible for you and your students
to avoid making these settings for each project.
General Rules for Projects
- When creating a new project, you must specify the proper type for
the project. Using IDE 1.6 (Codewarrior 9) I use ANSI C++ for either PPC or
68K, depending on hardware. You may be able to specify MacOs C++ also,
but using ANSI C++ will work using Codewarrior 9. With Codewarrior
version 12 there is a project type for Console C++ (or something
like this) that will work. With version 11 you should choose the
Console C++ project type also.
- Using the Edit menu, and the
submenu Preferences... option, find
the section for Language Settings,
choose C/C++ Language, then using
the button at the top of the page for Source Model, specify
ANSI C++.
- Using the Project menu, and the Add
Files option, add the .cpp files needed for the
project (this assumes you're NOT using APCS stationary and are adding
all .cpp files needed). You don't need to add .h files and you don't
need to add .cpp files that are implementations of templated classes
like apvector.cpp and apqueue.cpp. If you're only
using AP classes, you only need to add apstring.cpp since all
other AP classes are templated so shouldn't be added to the project.
You should add other .cpp implementations of classes you want your
students to have access to (but see the section on creating libraries
below). In a project there should be exactly one file
with a function main in it.
- When you've added the .cpp files, remove the file named something
like < Replace me ansi >.c. To remove it, select with the
mouse and use the Project menu,
Remove Files option.
Note that with version 9, you must add
new files first, then remove --- if you remove first the section for
source code will be removed as well (in version 12 you can remove
first).
- When you've added all the files, choose Run or
Make from the Project menu to compile, link, and run
the program. If you get link errors, be sure that all the necessary
.cpp files have been added to the project. If you have problems with
bool, you need to be sure that in any file in which bool is
used that the system-supplied header file bool.h is used:
#include
The angle brackets used with an include file tell the IDE to look for the file
as a system-supplied header file. The AP-version of bool.h will NOT work
with Codewarrior version 9. With version 12 (IDE 2.0) you don't need to
include the bool.h header file, bool support is built-in (at
least I believe this is the case).
Project Stationary
These instructions tell you how to create a library of all the AP
classes, and other classes you might want to use (e.g., Dice, Date, and
so on). Instructions are also provided for creating a new kind of
project stationary, so that users will have a choice of APCS
project when opening a new project. This will decrease
what students need to do to get a program up and running that uses classes.
Creating a Library of Classes
These instructions tell how to create a library of classes that students
can than link to their projects. Using a library, especially in a
networked environment, makes it easier to add class implementations when
you have a new class you want students to use. For the AP classes, you
can include apstring.cpp in the library --- this is the only AP class
that needs to be included since the other classes are templated and thus
shouldn't be in the library.
- Create a new project (under the File menu). Use a
name like aplib.prj, and make sure the project type is ANSI
C/C++ for the appropriate architecture.
- Using the Edit menu, and the
Preferences... submenu, make the Source Model for the
C/C++ language ANSI C++ (this is under Language Settings, using
the C/C++ Language option) -- see the menu/button at the top of the dialog.
You must change the project type too. To do this
choose 68K Project (or PPC Project as needed) in the
Project section of the Preferences. At the top of this
section, the Project Type must be specified as
Library using the menu there. In addition, you'll need to
specify a name for the file storing the library in the box labeled
File Name. I use aplib.lib. It's a good idea
to use the .lib suffix since most other libraries do.
- You should also change the access paths for
user code using the Preferences ... option. The
access path section is under the Project preferences. Click on each
item in the User section, then on the change
button. Make the paths either relative to the compiler, or absolute
path names. I'd choose relative to compiler first if the system lets
you do this. By making paths relative to the compiler, if you move the
compiler to a new folder then the library should still work.
- Now add .cpp files to the library project. Add all the .cpp files
you think you'll use, for example, during the workshop or that your
students will use during your AP course. You can always add more files
to the library later, especially if you have a network to facilitate
sharing the library or disseminating a new one.
For the workshop, I added apstring.cpp, bigint.cpp, clockt.cpp, dice.cpp,
prompt.cpp, rando.cpp, strutils.cpp, and systimer.cpp. (Don't forget to
remove the place-holder .cp file).
- Remove all sections except the source code section
(only the source is needed for the library). Then choose
Make from the Project menu --- you won't be able to
choose Run since you can't run a library.
- Once you've compiled the library, you're ready to create a project
using the library, and to create stationary from the project. Create a
new project, use ANSI C++ for the project type and use preferences to
specify ANSI C++ as the Language Model. Then, use add file and add the
file aplib.lib to the project. You should then add a test file
with a main function
(e.g., like letters.cpp from the workshop) to
test the library. You'll have only two files in the project that you've
added: aplib.lib and one file with a function main in
it. This project should build and run. You're then ready to create
stationary after you verify that the project runs.
- First change the access paths for all user entries in the
Preferences... section to be relative to the compiler
or absolute as described above.
- Create a file with a simple cout statement like "hello and welcome
to APCS". Save this in a program named
.cpp
Note the angle brackets are part of the real file name. This is the
convention used with Codewarrior. Add this file to the project as the
single file with a main function. Build and run the project. When it
works, choose from Save a Copy As from the
FILE menu. There's a pop-up choice for how to save the
file --- choose the Stationary option. The default suffix for
stationary is .stat, you probably should use this (I called my
stationary apcs.stat).
- When you've saved the stationary and the replace me file,
go to the finder so that you can copy files. Copy the apcs.stat
(or whatever you called it) to the folder named (Project
Stationary) in the Metrowerks Codewarrior folder ---
the parentheses are part of the folder name. You should also copy the
replaceme.cpp file to the subfolder named Project
Stationary Support. You should be set to go now. The next
time you ask for a new project, one of the choices should be
APCS, and this will likely be the first choice. You can move
all the other stationary out of the project stationary folder if you
don't want to give your students a choice of project type.
You should be sure to try the new project to make sure it works.