Carbonizing Pascal Programs
Ken Beath, Shareware Author

Carbonizing Pascal Programs

Introduction, by Bill Catambay

With Mac OS X, the big question for Pascal programmers writing code for the Mac is whether our Pascal applications can be ported to OS X so that they will run native. This process is known as Carbonizing your app, and there have been a few posts to the MacPascal mailing list outlining the steps for doing this using CodeWarrior Pascal. The most detailed list of instructions to date was offered by Ken Beath, and those steps are outlined below. In addition to these steps, Ken also included a CarbonStuff unit that you can use with your programs to support old toolbox calls.

Metrowerks has announced that work has begun on the final update for CodeWarrior Pascal which should streamline the process of carbonizing your Pascal programs, but there is no clear picture yet as to exactly what will be released. If you have success carbonizing your Pascal apps, please consider contributing your tales of success to the Pascal community so that we can all learn from your experience. I'm also looking for source code submissions of sample projects which have been carbonized. To contact me or submit source code, visit the
Pascal Central Submit page.

Instructions for Carbonizing Pascal, by Ken Beath

  1. Obtain the CarbonLib SDK and the Universal Interfaces - you can get either CarbonLib 1.0.4 and Universal Interfaces 3.3.x from (these should shortly be replaced by CarbonLib 1.1 and UI 3.4). Alternatively, you could join the ADC (Apple Developer Connection) and download the CarbonLib 1.2 and Universal Interfaces 3.4 as an online member. You need the Universal Interfaces as the Pascal interfaces aren't in CarbonLib SDK.

  2. Create a copy of the MacOS Support folder (somewhere in Codewarrior hierachy) and call it Carbon Support. Replace the Interface files and the stub libraries from the CarnonLib sdk. If your project includes C then rebuild the MacHeaders projects. Alternatively you can create an empty folder and only put the specificly Carbon files into it.

  3. In Codewarrior create a copy of your target. Change the Access Paths from MacOS Support to Carbon Support. If you used the Alternative method in 2 you will have to add Carbon Support as an access path.

  4. To your prefix file you will have to add

    {$setc TARGET_API_MAC_CARBON := true}
    {$setc CALL_NOT_IN_CARBON := false}

    There are several new things in the Universal Interfaces which may also have to be defined (especially if using CarbonLib 3.4). I've found that the following switches work

    {$setc TYPED_FUNCTION_POINTERS := false}
    {$setc GENERATINGCFM := true}
    {$setc PM_USE_SESSION_APIS := false}
    {$setc OPAQUE_UPP_TYPES := false}

  5. Add CarbonLib to your project for this Target. Exclude all other Apple libraries for this target (e.g., InterfaceLib, Mathlib, AppearanceLib, WindowLib, etc.).

  6. Your project probably contains the Metrowerks Standard Libraries.

    I obtained a replacement for MSL C.PPC.Lib from CW Pro 5. From the CW Pro 5 Reference folder Pre-Release:Carbon & MacOS X Development:Carbonized MSL, copy the appropriate files into the Bin folder in MSL. I just copied the LIBS. Change MSL C.PPC.Lib to MSL C.Carbon.Lib in your project.

    I didn't replace MSL RuntimePPC.Lib as replacing it with the only thing that looked sensible from CW Pro 5 gave me a link error.

    I didn't need SIOUX so I replaced it with console.stubs.c.

    I have been using the old Pascal.PPC.Lib (making this fully Carbon seems messy and for most people unneccessary). This uses some old names so I set up routines which call the correct names. Just link and fix up the undefineds.



    PROCEDURE IUDatePString(dateTime: LONGINT;
    longFlag: ByteParameter;
    VAR result: Str255;
    intlHandle: Handle);

    DateString(dateTime, longFlag, result,intlHandle);


    You will get some previously defined messages but as long as the message is ignored in Pascal.PPC.Lib this is OK. Otherwise, changing the build order should work.

  7. If you use objects then ObjInf.mac.p will need to be changed as LMGetApplZone is not defined in Carbon.

    In Ishandle, I have replaced the if HandleZone(h) <> LMGetApplZone then section with an isHandle := true;.

  8. Add a carb resource so it runs on Mac OS X. See Apple's Porting to Carbon notes.

  9. Convert all the other bits of your program. Most bits of this are simple once you get the hang of it. I have included a file CarbonStuff.p which may help (still being tested).

Copyright © 2000 Ken Beath. All Rights Reserved.