LoginSignup
1

More than 5 years have passed since last update.

How to correctly run Lazarus (the Free Pascal IDE) on Mac

Posted at

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:

  1. Install Prerequisites
  2. Install Free Pascal
  3. Install Lazarus
  4. Notes

Install Prerequisites

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:

$ sudo xcode-select --install

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:

$ sudo port install gdb-apple

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:

$ sudo chmod g-s /opt/local/bin/gdb-apple

Install Free Pascal

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:

hello.pas
program hello
begin
  writeln('Hello, world!');
end.

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

$ fpc hello
Free Pascal Compiler version 3.0.0 [2015/11/14] for i386
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Darwin for i386
Compiling hello.pas
Assembling (pipe) hello.s
Linking hello
4 lines compiled, 0.3 sec

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


$ ./hello
Hello, world!

Install Lazarus

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

Lazarus_-_Browse__Lazarus_Mac_OS_X_i386_Lazarus_1_6_at_SourceForge_net.png

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.

Notes

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

Lazarus_RunWarning.png

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:

Lazarus_IDE_Options.png

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1