Retired Document
Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Preparing a CodeWarrior Project for Importing
This section describes steps you can take to modify your CodeWarrior project before importing it into Xcode. Taking an incremental approach should make it easier to get your project building successfully in Xcode.
Convert Classic Applications to Use Carbon
If you have a classic application—that is, an application designed for versions of the Mac OS earlier than Mac OS X—you should convert your code to use Carbon. Carbon is a set of programming interfaces that allows applications (including those originally designed for Mac OS 8 and 9) to run natively in Mac OS X. If an application uses older Mac OS APIs that aren’t part of Carbon, it cannot run reliably in Mac OS X, except in Classic (or emulation) mode.
The amount of effort required to convert a project to Carbon depends on its complexity and on the programming tactics and Mac OS APIs it uses. For full information, see Carbon Porting Guide.
Use the Application Package Type
You should set the Project Type setting for your CodeWarrior project to Application Package. Packaging an application consists of putting the application’s code and resources in prescribed directory locations inside the application bundle.
To build an application as a package, you choose Application Package in the Project Type pop-up in the PPC Target pane. When you create a project from CodeWarrior stationery that uses one of the bundled types, such as “C Toolbox Carbon Bundle,” the Project Type is automatically set to Application Package.
Packaged applications require an information property list, named Info.plist
. The Information Property List and .plc Files describes this list, as well as differences in how to create it in CodeWarrior and Xcode.
Build the Application in the Mach-O Format
Mach-O is the native executable format in Mac OS X and is the only format supported by Xcode. Applications that use Mach-O format have access to all native Mac OS X APIs, such as Quartz and POSIX, and can more easily support symbolic debugging with GDB. However, Mach-O applications cannot run in earlier versions of the Mac OS. For a summary of the advantages and issues of using Mach-O format, see Use the Mach-O Binary Format in Performance Overview.
If your project currently builds a CFM application or library, you may want to add a target to the project to build a Mach-O version. This will allow you to isolate changes you’ll need for Mach-O before switching to Xcode. And you’ll still benefit from the automated setup performed when you import the project into Xcode. However, for a simple project, you may end up doing extra work.
Conversely, if your CodeWarrior project is not particularly complex, you may want to import it directly into Xcode (and switch to the Mach-O executable format at the same time). If you do, many changes will be handled automatically, including changing your linker settings and moving from MSL libraries to the standard C and C++ libraries. A disadvantage is that you’ll be making more changes in a new environment, where problems may be harder to isolate, so this approach isn’t recommended for more complex projects.
Whichever approach you take, you will still have some work to do after importing, as described in After Importing a Project.
Convert to Mach-O Format
C and C++ Libraries describes differences between the CodeWarrior MSL libraries and the standard C and C++ libraries for Mach-O. To build your application in Mach-O format, you’ll need to make these changes:
On the Target pane of the Target Settings window, change your Linker setting to “Apple Mach-O PowerPC” (preferred) or “Mac OS X PowerPC Mach-O”.
When you save your settings, CodeWarrior adds a Frameworks tab to your project window, if it didn’t already have one.
If you load plug-ins via CFM, you’ll need to rewrite that code to use the CFBundle or CFPlugin APIs.
You can read more about CFBundle in the document Bundle Programming Guide.
If your code makes assumptions about the size of the C++
bool
type, you may have to make changes: in Mach-O, abool
is four bytes wide, not one. See Make Code Changes for GCC Compatibility for details, and for other possible code issues.
The sections that follow list additional steps you’ll need to take in converting to use Mach-O format.
Use Framework Headers
Framework-Style Headers provides background on working with framework-style headers. To continue making the switch to a Mach-O target, you’ll need to take these steps to start using framework headers:
Remove
{Compiler}MacOS Support
from the Access Paths pane of the Target Settings window.Add necessary frameworks to your project. For example, you should include
System.framework
. You’ll probably also want to includeCarbon.framework
, and may need to include other frameworks, such asCoreAudio.framework
orOpenGL.framework
, if your project uses the APIs they define.Remember that the Carbon framework is an umbrella framework (it includes many other frameworks), so it may include most of the framework headers you need. Look in the header file
Carbon.h
within the framework for a complete list of the frameworks the Carbon framework includes.To add a framework, you can drag it from the Finder to the Frameworks tab in your project window. Or you can choose Project > Add Files and navigate to
/System/Library/Frameworks
.When you first add a framework such as the Carbon framework, CodeWarrior adds a path like the following to your access paths:
{OS X Volume}System/Library/Frameworks
These steps are recommended, but not required.
Remove all
#include <MacHeader.h>
statements from your source and header files.Use just the statement
#include <Carbon/Carbon.h>
in your prefix file. More information on the prefix file is provided in Replace Your Prefix File.
Use C99 Standard in Language Settings
Applications that change from using Universal Interfaces to using framework-style include statements (in either CodeWarrior or Xcode), must conform to the C99 standard, as described in Conform to the C99 Standard. In CodeWarrior, you can select the “Enable C99 Extensions” setting on the C/C++ Language pane in the Target Settings window.
Migrate from MSL to System C and C++ Libraries
C and C++ Libraries describes differences between the libraries you use in CodeWarrior and Xcode. To continue the switch to a Mach-O target, perform the following steps to change libraries:
Remove any MSL libraries (such as
MSL_All_CarbonD.Lib
) from the Libraries folder in the Files tab of your project.Remove any access paths to MSL libraries from the Access Paths pane of the Target Settings window for the target.
Add paths to the Access Paths pane for
{OS X Volume}usr/include
and{OS X Volume}usr/lib
.Add the file
/usr/lib/libSystem.dylib
to your project. This is a symlink that will resolve to the appropriate version of the system library.You may need to add the file
crt1.o
(located in/usr/lib
) to the project and make it the first file in the Link Order settings tab.
Replace Your Prefix File
Precompiled Headers and Prefix Files describes differences in how you use prefix files in CodeWarrior and Xcode. To continue the switch to a Mach-O target, you’ll have to move away from the CodeWarrior precompiled headers. You can do that in one of two ways:
Make your own prefix file and precompile it. As mentioned in a previous section, some projects can use just the statement
#include <Carbon/Carbon.h>
in your prefix file. Of course you may need to construct a more complex prefix file.In the C/C++ Language pane of the Target Settings window, enter the name of your file in the Prefix File text field.
Or you can modify the source for the CodeWarrior precompiled header so that it precompiles against the headers in
/usr/lib
, rather than the MSL headers, then re-precompile it.
Test Your Mach-O Target
At this point you should be ready to test your Mach-O target.
Remove Unnecessary Targets From the Project
To simplify the conversion process even further, you can make a copy of the project and delete any targets other than the targets you will import into Xcode. That will make importing faster and the resulting project will have just the desired target. Of course, you can also delete unneeded targets after importing into Xcode.
Copyright © 2003, 2009 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2009-06-30