This will work with Lazarus 1.8. Free Pascal Tutorials: Free Pascal & Lazarus Download: First Instal.
│English (en) │
Lazarus is a free and open source development tool for the Free Pascal Compiler. The purpose of this project is to serve as a Code Repository, Wiki Knowledgebase and support site for converting existing components and libraries to work with Lazarus and the Free Pascal Compiler. Lazarus is a free cross-platform visual integrated development environment (IDE) for rapid application development (RAD) using the Free Pascal compiler. Its goal is to provide an easy-to-use development environment for programmers developing with the Pascal Object language, which is. My route was to install Xcode 4.3 on an old Mac Mini running snow leopard, then install Lazarus using the fink version as described here. This took a while but was done in an evening. Then I just copied my folder across to the Mac, opened the lpi on the Mac, compiled it. It failed so I removed a windows references, recompiled, and it was working.
This article applies to Mac OS Classic only.
See also: Multiplatform Programming Guide
MacOS is the target for Mac OS Classic, i.e. the predecessor to macOS. macOS itself was previously marketed as Mac OS X and OS X. For macOS, see Target Darwin.
- 2Some tips
- 5Cross compiling from Mac OS X to Mac OS
Compiling in MPW
Free Pascal can now be used in the MPW development environment.
Free Pascal for MPW call assembler and linker via ToolServer. This means that you need ToolServer installed. This will normally not be an issue, since ToolServer is included in the MPW distribution.
In rare instances, you might get the error message 'Can't call the assembler, switching to external assembler.' I do not know the origin of this, but it will help to restart. On Mac OS X you might need to restart even OSX. It might also indicate that you need to increase the memory setting for ToolServer.
Another workaround for such problems is to let the compiler write out an MPW script (option -s). This will assemble and link when executed in MPW. This method can also be used if the compiler is to be called from a third program, to overcome the deadlock situation mentioned below under Dos.Exec.
For crosscompiling e.g. from macOS to Mac OS Classic, see below.
Some tips
Choosing apptype
For casual users, copying Pascal text only programs from a book, {$APPTYPE CONSOLE} is appropriate.
If you want an MPW tool, use {$APPTYPE TOOL}.
For maximum portability, the following:
... ensures it will be an MPW tool on Mac OS, and a console application in Delphi where {$APPTYPE TOOL} is not recognized.
Resources
Since 24-01-2004 mac style resources can be included with {$R <resfile>}. If the resource file ends with .r it is considered a Rez type resource file (in text form). For all other files (including .rsrc), binary resources are assumed. Several resource files can be included.
Error messages
Errors, warnings, hints and other messages written by the compiler are in MPW format - that is you can execute them and the error location will be displayed.
Dos.Exec
The procedure Dos.Exec is used to execute other programs. In MacOS this is supported, and the program(s?) which can be executed is MPW tools. An AppleEvent is sent to ToolServer which in turn executes the tool. A limitation is that ToolServer is not reentrant, so if a program which is called via Dos.Exec, in turn call Dos.Exec, it will be deadlocked.
Assembler symbols
Internal symbols in the generated assembler files will have a lowercase 's' as part separator instead of '$'. The reason is that PPCAsm does not support $.
QuickDraw globals
There is a variable qd defined in System.pp for use as the QuickDraw global.
For {$APPTYE TOOL} and {$APPTYPE CONSOLE} it is initialized, but for {$APPTYPE GUI} you have to initialize it yourself.
Debugging
See MPW debugging
Global variables
Currently all global variables are indirect, i.e. the entry in the TOC is always a pointer to data. (In the future small data items may be stored directly in the TOC)
Thus all references to globals are via a construct like: lwz rX, yyy[TC](r2) ;loads a pointer to a global into rX
Cross compiling from Mac OS X to Mac OS
Although not necessary nowadays when there exists a native compiler for target MacOS, here is some info on how to cross compile. See also Link on target.
Crosscompiling step on macOS
When compiling, add these options:
If make is used, add OPT=-st OS_TARGET=macos
Note that one must first build the RTL by issuing make in rtl/macos, with the above options, to be able to build other programs. The RTL must then be assembled and linked (see below) before compiling any program, otherwise the search paths in the link script will not be correct.
Lazarus Macos Mojave
You might also want to add option -a, then the link script will not delete unneeded files, in particular the assembler files (*.s). This can be useful if there are problems with the link scripts and you want to rerun it.
Assembling and linking step on Mac OS Classic
In case that host and target machine is different, transfer the produced files (assembler files (*.s) and link script *_ppas) to the host.
In Mac OS Classic, use MPW to assemble and link the output from FreePascal by executing the link script (which is an MPW script), with its directory as current directory. Unfortunately the link script does not(?) obtain the proper mac file type, so this has to be fixed first e.g. with the MPW command SetFile.
Example: To build Hello World (together with the rtl unit system.pp), execute:
Above circa 2004/5.
Working notes: situation as of late 2012
The objective here is to build PPC and possibly 68K compilers, first as cross-compilers to run on a PC and then to run natively on Mac OS 9. Part of the incentive for this is to investigate whether a PPC Mac, e.g. my (MarkMLl) G3 beige with 'Old World' ROMs, is a usable testbed for the fixed 68K compiler which Sven has added to trunk at around 2.8.

On e.g. Debian Linux, build and install cross-binutils:
Do the same for m68k-linux-gnu.
Build a cross-compiler to run on a PC but targeting PPC:
Renaming the compiler prevents it from being deleted by make clean etc., consider extending that OPT setting with -dEXTDEBUG.
Build a native RTL and compiler:
Bringing macos/sysdir.inc up to date shows that the amiga, embedded, watcom and symbian OS targets are similarly falling behind. It's instructive to compare the amiga target (which has not been updated) with the morphos target (which has).
There's also a problem inside the compiler itself where entries of type AT_NONE are being generated but not handled.
To be continued.
Welcome to the FreePascal on the Macintosh page. Here is information especially for you who want to write a program for the Macintosh.
News:
2009-02-09:The download statistics indicate that the snapshots below are still downloaded a lot. Note that all fixes from those snapshots are also in the official release of FPC 2.2.2 (and will be also in later versions, when they become available), which was released in August 2008. Since FPC 2.2.2 also contains many additional fixes, we recommend you to use that version. It is available from the regular download pages.
2007-11-14:
There are some errors in the new linker shipped with Xcode 3.0/Mac OS X 10.5. A detailed overview was posted to the fpc-pascal mailing list. We have worked around most of those issues and created (stable) development snapshots for both PowerPC and Intel. These are intended to be installed on top of the 2.2.0 release version. Future releases will have these fixes incorporated.
One linker bug cannot be completely worked around in the compiler, which is related to the Stabs debugging format. For this reason, we recommend to switch to the Dwarf debugging format on Mac OS X 10.5. On the command line, you can do this by using -gw instead of -g to generate debugging information. In the Xcode projects, add -gw at the end of the FPC_SPECIFIC_OPTIONS project setting for the Debug configuration.
2006-08-27:Regular snapshots of FPC 2.1.1 (both for PowerPC and for Intel - the latterdenoted as i386) are now generated by and available from the Lazarus team.
If you only need the compiler (to either use it from the command line or from Xcode),you only have to download and install the 'fpc' package.
2005-12-18:
Version 2.0.2 that was released a few weeks ago has all fixes and improvements of the 2.1.1 snapshot that was here (like Mac Pascal style objects and creationof dynamic libraries). Additionally, it doesn't suffer from the installationproblems the 2.1.1 snapshot installer had. Get the release here.
2005-07-23:
The 2.1.1 snapshot that was here is no longer available.
If you really need to be up to date with FPC,please consider using Subversion, and build the compiler by your self.
Some changes:
- No more '_main' symbol in the system unit (so can link with C main programs)
- Shared library creation support under Mac OS X
- Several bugfixes related to overflow checking on PPC
There is now a wiki page covering porting issues, from traditional mac pascals to FPC.
2005-06-21:
A FPC 2.1.1 snapshot is available here (10.8 MB, does not include the PDF documentation). It includes:
- Support for Macintosh Object Pascal in Macpas mode (includes support for mixing in Delphi-style OOP programming in Macpas mode, except that you have to use 'object' instead of 'class' everywhere -- all occurrences of 'class' are simply internally replaced by the _OBJECT compiler token)
- Fixed bug which caused stack corruption in procedures receiving floating point parameters and parameters on the stack (only if the caller side was compiled by FPC)
- Fixed bug in overflow checking of integer operations (some calculations were buggy if overflow checking is turned on, which is the case in the default development building style of Xcode if you use the integration kit)
- Fixed bug in division of unsigned numbers > $7fffffff by a power of 2
2005-05-15:At last !!!!! Free Pascal 2.0 is released for Mac OS X and classic Mac OS,as well as for other targets.
This means Free Pascal for the mac is not considered beta anymore.Get it on one of the mirror download sites.
Targets on the Macintosh:
Target / Processor | Status | Remark | Contact |
|---|---|---|---|
final | For Mac OS X | ||
final | Target Mac OS means classic Mac OS, up to System 9.x. Although it of course also work in the classic environment in Mac OS X | ||
Mac OS on M68K | not planned | If someone is interrested to contribute, there is a possiblity to implement this target. There is support for MC68000 in the FPC source code, although not updated for a while. |
Mac Pascal dialect
The dialect of Pascal supported by popular Pascals on Macintosh is supported in part. Read more here.Free Pascal 2.0 for Mac OS X is the current release. It should at least work on Mac OS X 10.1 and higher. It requires that you have installed XCode from Apple, to have assembler, linker and make tools available to fpc. For older versions of Mac OS X you should install Apple Development Tools instead. Both can be downloaded for free from Apple, but requires that you register yourself as a member of Apple Developer Connection. Both are also included in the Mac OS X bundle.
To download, go to the Download page, and choose a mirror site near you (to limit net traffic). The documentation is included, but can also be downloaded separatelly. If you want the source code, it has to be downloaded separatelly.
There most recent FPC 2.1.1 snapshot is available here (10.4 MB)with, among others, support for mac style object pascal. See above under NEWS.Note that the compiler is a unix style program and is run from the Terminal on Mac OS X.
Please report any bugs encountered.
Using FPC from XCode
It is possible to use Free Pascal from within XCode (Mac OS X 10.3 is required).Look at the step-by-step instruction of how to download and install the XCode Integration Kit. Thanks to Rolf Jansen for this contribution.Free Pascal 2.0 for Mac OS is the current release. It will work on latest classic Mac OS (that is 9.2.2) and below, probably down to 7.1.2 (the first Mac OS for PowerPC), and also in the classic compatibility environment on Mac OS X. However it has only been tested on Mac OS 9 and Mac OS X classic environment.
It requires that you have installed Macinstosh Programmers Workshop (MPW) which can be downloaded for free from Apple.
To download, go to the Download page, and choose a mirror site near you (to limit net traffic). The documentation, as well as the source code (if you need it), has to be downloaded separatelly.
Note that the compiler is an MPW tool.
Please report any bugs encountered.
Current status of classic Mac OS
Native FPC compiler (as an MPW tool) | Almost complete | |
Unit System.pp | Complete | The system unit is implicitly used by every program. Contains basic file and memory handling among others. |
Unit Dos.pp | Complete | Contrary to what its name suggests, the DOS unit is cross plattfrom and contains utility routines for file and date handling, beyond that in System.pp. It is reminiscent from Turbo Pascal. |
Unit Sysutils.pp | Planned | A moderner alternative to unit DOS, compatible with Delphi. |
Unit MacOS | Complete | API to the Macintosh Toolbox |
Units strings objpas heaptrc getopts etc | Implemented. | They are target independent. |
Other units | Non-existent. Some will be implemented. | Implementation will depend on how important the unit is and if difficulties arise. |
Debugging
There is some limited possibilities to debug programs in classic Mac OS. See MPW debugging in the wiki.
As an alternative, you might do the main debugging in a Mac OS X/Darwin version of your program.
There are three major Pascal dialects: Turbo Pascal (extended to Delphi, supported by FreePascal, and partially by Gnu Pascal), Extended Pascal (an ISO standard, supported by Gnu Pascal, DEC Pascal, Prospero Pascal), and the dialect originating from Apple (commonly used in the Mac community, supported by MPW Pascal, Metrowerks Pascal and Think Pascal). We call this dialect Mac Pascal and there is a special language mode for it: MacPas.
Mode MacPas is a compatibility mode. It is probably not possible to mimic the Mac Pascal dialect in detail. So the goal is to implement often used constructs, if this doesn't require too much effort, as well as easy-to-implement constructs.
Lazarus Ide Mac Os
To use MacPas, add -Mmacpas to the command line or insert the compiler directive {$MODE MACPAS} in the source code.
Note that the mac pascal dialect and mac targets are not interrelated. It is thus possible to write a mac program with the turbo dialect and to write a Windows program with the mac dialect.
The following are supported: Mac compiler directives like $SETC, $IFC, $ELSEC, $ENDC, $J, $Z. Most of the constructs found in interface files, especially Apples Universal Interfaces. Cycle, Leave, Otherwise. More is planned.
More updated info on the Wiki page.
By Olle Raab
For questions and suggestions, we suggest subscribing on our mailing lists , in particular FPC-pascal for questions about using Free Pascal.
Or write to olle.raab@freepascal.org
Lazarus For Mac Os Versions
Latest modified 2005-07-28
