The third issue is that the official Lazarus Mac OS X i386 download for Lazarus 2.0.10 was compiled with FPC 3.0.4 and not FPC 3.2.0. The solution is to download the Lazarus release sources to your home directory. But in Lazarus, only Enter does; pressing Tab instead does something closer to bash commandline completion, filling in a partial identifier string without closing the listbox. Due to muscle memory from VS, when using Lazarus I keep pressing Tab to pick an item from the listbox, and it doesn't work the same way, and I'm like 'grr'. This portal provides an overview of development for macOS (previously marketed as Mac OS X until 2012 and OS X until 2016) with Lazarus and Free Pascal. Development of macOS software is easy with Lazarus using the Cocoa (64 bit) widgetset. The Carbon widgetset is also available but only for 32 bit software and only up to macOS 10.14 Mojave. Has anyone used Bluetooth on Mac OS X with Lazarus or FreePascal? There is a bluetooth unit, but it currently only supports Linux. Note: Mac OS X doesn't appear to use the BlueZ library that Linux has, so I don't think the solution is as easy as changing the library path. Instead, it has IOBluetooth 'Framework', located at /System/Library.

  1. Lazarus For Mac Os X64
  2. Lazarus For Mac Os X 10.10
  3. Lazarus For Mac Os X 10.7

English (en)

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

Lazarus for mac os x64

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

Lazarus for mac os x64

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.

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.

Retrieved from 'https://wiki.freepascal.org/index.php?title=Target_MacOS&oldid=129380'

This article describes how to correctly run Lazarus (the Free Pascal IDE) on Mac.

Environment:

  • Hardware: MacBook Pro (Retina, 13-Inch, Late 2013)
  • OS: OS X El-Capitan version 10.11.6 (15G31)
  • Package Manager: MacPorts version 2.3.4

You will need to install MacPorts and selfupdate as needed. MacPorts is used to install gdb (debugger). If you use Homebrew, though I have not confirmed it is working, you may use it to install dbg (there is a note on the Free Pascal website explaining about using Homebrew to install gdb).

Installation steps:

Lazarus for mac os x 10.13
  1. Install Prerequisites
  2. Install Free Pascal
  3. Install Lazarus
  4. Notes

Apple Developer tools

You need the Apple Developer tools, which are part of the XCode development environment. If you don't have it installed, you can execute the following terminal command:

Lazarus For Mac Os X64

Debugger (gdb)

You need a debugger to use Lazarus, the Free Pascal IDE. You can use gdb which was included in the Apple Developer tools but it is no longer included in the newer versions of the tools. In this article, I will explain how to install gdb using MacPorts. You may use Homebrew or other package manager or even build by your self.

There are two versions of gdb from MacPorts, one is the original GNU gdb and the other is customized for Mac environment. I will use the latter one. Install the gdb using the following terminal command:

The gdb command is installed at /opt/local/bin/gdb, which is linked to /opt/local/bin/gdb-apple.

The next thing you have to do is codesigning the gdb and make a modification to the file permission, in order to use it in Lazarus.

To codesign the gdb, you may refer to this page.

After that, you need to change the file permission of the gdb command file, the /opt/local/bin/gdb-apple, using the following terminal command:

You can install Free Pascal by downloading the installer from their website. You choose the appropriate edition for your Mac. When the installation of Free Pascal is finished, you can confirm the compiler using terminal commands.

Suppose you have written a simple pascal code like this:

Then, from terminal, you can run the following command:

After that, you can run the program as simple as this:

To install Lazarus, you can download the installers from this page.

Lazarus For Mac Os X 10.10

You need to install three components here. First, the Free Pascal compiler, which we have done in the previous step above. The rests are the Free Pascal source codes fpcsrc and the Lazarus application lazarus itself.

Thats it. We can now start using Lazarus to develop program using Free Pascal.

When you run a project from within the Lazarus IDE, you may encounter this dialog:

Lazarus For Mac Os X 10.7

It seems that there is a bug in the dbg. You can just ignore this dialog. You can also configure to not displaying this dialog again by setting the WarnOnTimeout to False in the IDE Options: