Macintosh Programmer's Workshop

This page is a collection of my notes on using Macintosh Programmer's Workshop (MPW) and associated tools, such as the MrC and MrCpp compilers, which I have used since 2017. Unless noted otherwise, all notes assume the last versions of Mac OS 9, the MPW shell, and associated tools (which are not necessarily the "golden master" versions).

Bugs in MrC

Sometimes you may get a compiler warning that is an empty string. The cause may be one of the following:

The compiler may have trouble compiling code using variables of type long long or too complicated expressions, reporting internal errors. Breaking up code into more simple expressions (and using narrower types if possible) will usually solve the problem.

The compiler may fail to warn you if you are calling a function with a different number of parameters than declared or if some of them are of the wrong type.

Some functions may produce an internal error when compiled with optimizations or will produce incorrect code. In both cases, a workaround is to put #pragma options opt level into the function body (usually at the top); level is off or preferably local (this still optimizes a little and usually works fine).

Bugs in MrCpp

(In addition to those also present in MrC.)

MrCpp may sometimes forget to generate a v-table for a class with virtual methods, causing linker errors.

A workaround (which usually works, but not always) is to insert a declaration (not a definition!) of a dummy method as the first member of the class, such as void Dummy ();, then later define it outside the scope of the class, such as void class::Dummy () {}.

The compiler does not allow loop-local variable scope by default. For example, if you have two or more loops like for(int i = 0; i < n; i++) in the same function, the compiler will complain that i is already defined. Use the option -ansifor to prevent this error. (You may have to use a newer MrCpp than comes with MPW 3.5.)

When using STLport container classes (e.g. std::vector), MrCpp will sometimes require an explicit default constructor (with no parameters) to be provided. I don't know whether this is an issue with MrCpp or STLport.

Compiling large files may crash your computer if the MPW shell doesn't have a large enough stack. You can increase it with the SetShellSize command. (This is probably also possible with MrC, but it has only happened to me with MrCpp so far.)

Bugs in StdCLib

(StdCLib is the implementation of the standard C library for MrC and MrCpp.)

If you call ftell on a file immediately after fflush ("immediately" meaning that no I/O has been done on the file between those calls), you will get an incorrect result.

Using SDL

To compile the SDL library (version 1.2.15, the last supporting Mac OS 9 and older):

  1. Install the OpenGL SDK. (One way to obtain it is from this mirror.) Copy the libraries and headers into the appropriate folders in your MPW installation.
  2. In MPW, execute Set -e CIncludes "{CIncludes},{CIncludes}OpenGL:" to let the compiler find the OpenGL headers. (You can also change this variable permanently if you are going to use OpenGL, but for the purpose of compiling SDL, it is not necessary to do so.)
  3. Follow the instructions in SDL's README.MacOS file. Note: by default, the library will be compiled without full optimizations. You can edit the makefile (SDL.make) and put -opt speed into the compiler options at the top.

To compile SDL applications, link with the produced SDL library and optionally SDLmain.o (unless you initialize the Macintosh Toolbox yourself). SDL requires that you use the -enum int compiler option. The compiled application will require the SDL library in its folder.

Using STLport with MrCpp

MrCpp does not come with an implementation of the C++ standard template library (STL), so a third-party one is needed. One such implementation is STLport.

It seems that using STLport with MrCpp was possible up to at least version 4.5.1, but the patches are lost. (If you have them, please get in touch.) However, it is still possible to use version 4.0, which you can get from the archive.

GUSI, Sfio, and other libraries

GUSI is a library providing implementations of several POSIX functions on Mac OS to ease porting software.

Sfio is an implementation of stdio.h functions that is required by GUSI when used with MrC and MrCpp. You can get it here and possibly elsewhere.

Using Free Pascal

The last version of Free Pascal for Mac OS and MPW is 2.0.4. (I have succeeded in compiling neither it nor a newer one.)

If you are using the MacOS unit in your Pascal program, give MPW at least a 32-megabyte memory partition.

If the path of your MPW installation contains spaces, linking a Pascal program will fail. The workaround is to either get rid of the spaces or the following:

  1. Compile your Pascal program with the -sh option.
  2. Edit the link.rel file and put quotes around the names of the object files.
  3. Execute the ppas script.

My MPW tools

My MPW scripts

Open source software ported by me to Mac OS in the form of MPW tools

Links


First published on .
Last updated on .

Table of contents

Contact me