Difference between revisions of "Installing Lazarus on macOS"

From Lazarus wiki
(Step 4 FPC, FPC Source and Lazarus)
m (Downloading Lazarus Fixes 2.2 source: Tweak svn command (old one also works))
 
(256 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{Platform only|macOS|macOS|macOS}}
+
{{Installing Lazarus on macOS}}
{{Installing Lazarus on MacOS X}}
 
  
Installing Lazarus on a Mac is not particularly difficult but is a bit tedious. Its critical that you do the install in the correct order.  Skipping steps will almost certainly lead to tears. In brief, here is what you do -
+
Installing Lazarus on a Mac is not particularly difficult but it is critical that you do the install in the correct order.  Skipping steps will almost certainly end in tears. In brief, here is what you need to do:
  
# Download and install Xcode.
+
# Download and install Xcode (optional depending on your needs - see below for details).
 
# Install the global command line tools for Xcode.
 
# Install the global command line tools for Xcode.
# Install gdb - sort of but not really optional.
+
# Download and install the Free Pascal Compiler (FPC) binaries and the FPC source from the [https://sourceforge.net/projects/lazarus/files/ Lazarus IDE file area] ('''Important''' do this ''before'' you install the Lazarus IDE)
# Install Free Pascal Compiler, FPC Source and Lazarus
+
# Download and install the Lazarus IDE  from the [https://sourceforge.net/projects/lazarus/files/ Lazarus IDE file area]
# Speak to Lazarus about gdb.
+
# Configure LLDB - the Apple supplied (and signed) debugger from within the Lazarus IDE.
 +
 
 +
These steps are explained in more detail below.
 +
 
  
  
 
== Installation ==
 
== Installation ==
  
The detailed instructions assume a recent version of OSX on you Mac, a recent version of Xcode from Apple and recent version of Lazarus. Further down the page, under Legacy Documentation, you will see older information that may be relevant if you are using older components. You can assist by replacing out of date info, either deleting it, or, if it may help someone working with a legacy project, moving it to bottom of the page.
+
The detailed instructions assume a recent version of macOS on your Mac, a recent version of Xcode from Apple and a recent version of Lazarus. On the [[#Legacy_Information|Legacy Information]] page, you will see older information that may be relevant if you are using older components. You can assist by replacing out of date information, either deleting it, or, if it may help someone working with a legacy project, moving it to the [[Legacy_Information:_Installing_Lazarus_on_Mac|legacy information]] page.
  
In general, this is about using the '''Carbon Widget Set''', it is intentionally (by Apple) limited to 32 bits and we have every reason to believe Apple may drop support for it some time in the not too distant future. The alternative is '''Cocoa''', more information to be provided.  
+
In general, this is about using both the '''Carbon''' and '''Cocoa''' Widget Sets. While Carbon was once seen as a little more stable, with the release Lazarus 2.0.8 the 64 bit Cocoa Widget Set has now surpassed Carbon and should be considered seriously for any new projects. Carbon was intentionally limited to 32 bits by Apple and you should be aware that it and the ability to run 32 bit executables have been removed completely from macOS 10.15 Catalina and later versions which now only support 64 bit executables using Cocoa.  
  
=== Step 1. Download Xcode. ===  
+
=== Step 1: Download Xcode (optional) ===
You need the Apple Developer tools, which are a part of the XCode development environment. They can be installed from the original Mac OS X installation disks or or a possibly newer copy downloaded from the Apple Developer Connection (ADC), which requires free registration: http://developer.apple.com/ Download the Xcode file, it will end up in your Downloads directory as an xip file. September 2017 it is Xcode_9_beta_6.xip, about 5G. Click it. It is unarchived into your Downloads directory. You may be happy with it there but maybe not. Other users will see the path to it but be unable to use it. And its untidy there. So I moved mine and then told xcode-select where it was moved to (in a terminal) -
 
  
<syntaxhighlight>mv Downloads/Xcode-beta.app /Developer/.
+
Xcode is a 12GB download which will take up 16GB of disk space. You '''only''' need to download and install the full Xcode development environment '''if''' you need:
sudo xcode-select -s /Developer/Xcode-beta.app/Contents/Developer </syntaxhighlight>
 
  
=== Step 2. Xcode Command Line Tools ===
+
* the SDKs for '''iOS''', '''iPadOS''', watchOS and tvOS; or
This is shown here as a separate step because it really is a separate step in addition to Step 1. Don't confuse this with the internal Xcode command line tools that the Xcode GUI will tell you are already installed. Lazarus cannot use those Xcode internal command line tools, so do the following (its quick and easy)-
+
* to validate and upload apps to the Mac App Store; or
 +
* to [[Notarization for macOS 10.14.5+|notarise]] apps for distribution outside of the Mac App Store.  
  
<syntaxhighlight>xcode-select --install</syntaxhighlight>
+
Xcode 11.3.1 for use on macOS 10.14 Mojave must now be installed by downloading it from [http://developer.apple.com/ Apple Developer Connection] (ADC), which requires free registration.  Xcode 12.4.x for use on macOS 10.15 Catalina and macOS 11 Big Sur can be installed from the [https://apps.apple.com/us/genre/mac-developer-tools/id12002?mt=12 Mac App store]. Note that you must first move any old Xcode versions from the Applications folder into the trash or rename the Xcode app (eg Xcode.app to Xcode_1014.app). You can then select which version of Xcode to use with the command line utility <tt>xcode-select</tt>. Open an Applications > Utilities > Terminal and type <tt>man xcode-select</tt> for this utility's manual page.
  
Since macOS Mojave you need to install the DSK headers as well:
+
'''Older systems:'''
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
 
  
=== Step 3 install gdb ===
+
The Xcode developer tools can be installed from the original macOS installation disks or a newer copy downloaded from the [http://developer.apple.com/ Apple Developer Connection] (ADC), which requires free registration. Download the Xcode file, it will end up in your Downloads directory as a zip file. Click it. It is unarchived into your Downloads directory. You may be happy with it there but maybe not. Other users will see the path to it but be unable to use it. And it is untidy there. So I moved mine and then told xcode-select where it was moved to (in a terminal) -
While this is really optional, I suggest you do need gdb in most cases and I recommend this step. Alternatives include -
 
* No debugger. In Lazarus 1.8 you can choose Run->Run without Debugger or set it up to always run without debugger. OK if you are building code developed elsewhere and certain to build cleanly (yeah, thats likely).
 
* Use the Apple provided debugger, lldb, sounds like thats practicable only when making simple command line apps. https://developer.apple.com/library/content/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/lldb-terminal-workflow-tutorial.html
 
* Move your project into Xcode, https://macpgmr.github.io/ObjP/ProjectXC.html might not be a great idea if you are doing a cross platform app. Any one worked this way ?
 
  
Getting gdb to run can be a bit tedious but is worthwhile in the end. I recommend this approach
+
<syntaxhighlight lang="bash">mv Downloads/Xcode.app /Developer/.
# Install fink or brew and use them to install gdb- http://wiki.freepascal.org/GDB_on_OS_X_Mavericks_and_Xcode_5
+
sudo xcode-select -s /Developer/Xcode.app/Contents/Developer </syntaxhighlight>
# Self sign the gdb binary using tools already on your Mac - https://sourceware.org/gdb/wiki/BuildingOnDarwin This is the tedious part. The instructions are clear except, perhaps they could have mentioned that after you have set the Keychain to ’System’ you need click ‘Create’ and ‘Done’ on the next screen. Then go and find the cert in your overall list of certs to do the next instruction “using the contextual menu…”. Don’t worry about step “2.1.4 Disable starting the debuggee…”, we’ll address that once Lazarus itself is installed and working.
 
# Once Lazarus is installed and fired up, tell it how it should start gdb, that is step 5.
 
  
'''Note''' that as of April 2018, there may be issues with newest gdb and High Sierra. https://forum.lazarus.freepascal.org/index.php/topic,40874.0.html
+
=== Step 2: Xcode Command Line Tools ===
''According to https://stackoverflow.com/questions/49001329/gdb-doesnt-work-on-macos-high-sierra-10-13-3, gdb 8.1 does not work on High Sierra, but 8.0.1 does.''
 
  
=== Step 4 FPC, FPC Source and Lazarus (disk images or fink) ===
+
This is shown here as a separate step because it really is a separate step. Don't confuse these standalone command line tools with the internal Xcode command line tools that the Xcode GUI will tell you are already installed if you installed the full Xcode package in Step 1. FPC cannot use those Xcode internal command line tools without configuration changes (see [[Xcode]] for details).
Get and install, '''in this order''', the FPC, FPC Source, Lazarus. Get release version of all three from Link https://sourceforge.net/projects/lazarus/files . As these install kits are not approved by Apple, you need to hold down the Control key, click the package and choose Open and confirm you want to install from an Unknown Developer (i.e. one who does not pay Apple a kickback).
 
  
Alternatively, you can use [http://finkproject.org/ fink], a package manager for Mac OS X. The extra bonus of fink is easy installation as well as clean removal of a huge number of other open source software packages, including [[Cross_compiling#From_Darwin_to_Windows.2C_Linux_and_others | FreePascal crosscompilers ]] for many processors and systems. The choice for lazarus is between a carbon look of lazarus (preferred by most), a gtk2 look, a Qt4-based and a Qt5-based version:
+
Do the following, it is quick and easy for all macOS versions up to and including Catalina 10.15:
  
$ fink install lazarus-aqua
+
<syntaxhighlight lang="bash">
 +
sudo xcode-select --install
 +
sudo xcodebuild -license accept
 +
</syntaxhighlight>
  
or
+
For Big Sur 11.x, you only need to enter the first of the two commands above unless you have also installed the full Xcode package. If you have only installed the command line tools, you should omit entering the ''xcodebuild'' command.
  
$ fink install lazarus-gtk2
+
If you have problems installing the command line tools using this command line method (eg the installer freezes while "finding Software"), you can also download and install the command line tools package by logging in to the [https://developer.apple.com/download/more/?=for%20Xcode Apple Developer Site] and downloading and installing the ''Command Line Tools for Xcode'' disk image.
  
or
+
=== Step 3: FPC binaries and FPC source code ===
  
$ fink install lazarus-qt4
+
{{Note| For installation on Apple Silicon/AArch64, after installing the 64 bit Intel binary and source for FPC, please refer to [[macOS_Big_Sur_changes_for_developers#ARM64.2FAArch64.2FApple_Silicon_Support|these instructions]] for building a native Apple Silicon Free Pascal Compiler.}}
  
or
+
Download and install the Free Pascal Compiler (FPC) binaries and the separate source package. A compatible FPC (and source) must be installed ''before you install'' Lazarus. You have a number of options.
  
$ fink install lazarus-qt5
+
==== Source Forge (Official Repository) ====
  
You will be asked, whether to install a number of dependencies, including the FreePascal compiler, the lazarus sources. Simply hit RETURN at the prompt and go for a coffee. It may take quite some time to build all packages, in particular on older Macs.
+
Download the official Free Pascal Compiler (FPC) binaries and FPC source packages from the [https://sourceforge.net/projects/lazarus/files/ Lazarus IDE file area].  
  
After installation, Lazarus can be started from the folder /Applications/Fink/. The actual details of fpc and lazarus are in subdirectories of /sw
+
When you arrive at that file area:
  
With any lazarus package from fink, these widget sets are supported for your program on macOS:
+
# Choose the correct version of your operating system. The vast majority of Mac users should now choose the 64 bit packages in the Lazarus macOS x86-64 directory. Every Mac computer since late 2006 has been 64 bit capable. The fact that Apple has completely dropped all 32 bit support from macOS 10.15 Catalina (released in October 2019) is another reason to choose the 64 bit packages.
 +
# Choose the version of Lazarus you wish to install and you will be presented with the FPC binary and source packages to download.
  
carbon (Aqua), gtk2, qt4 (Aqua), qt5 (Aqua), nogui, win32, win64 and wince.
+
These installation packages are built by the FPC/Lazarus developers and track formal releases. As these installation packages are not approved by Apple, you need to hold down the Control key, click the package and choose Open and confirm you want to install from an Unknown Developer.
  
=== Step 5 Tell Lazarus about starting gdb ===
+
You might like to try a simple and quick test of FPC at this stage - [[Installing_the_Free_Pascal_Compiler#Testing_the_FPC_Install|Testing FPC installation]].
OK, now you should be able to start Lazarus, it should display the various parts and paths it needs (including gdb) in the little opening screen. You will get an alert there if you chose to not use a debugger. Proceed to the IDE and we now need to tell Lazarus to tell gdb to not open a shell, as noted by a number of Forum people (http://forum.lazarus.freepascal.org/index.php/topic,37310.0.html). Within Lazarus, click Tools->Options->Debugger->General
 
In the “Debugger specific Options” there is a field labeled Debugger_Startup_Options. Type in "--eval-command=set startup-with-shell off" (including the inverted commas) AND press the return key, click OK. Note you cannot copy and paste into this box (##$!). See screen shot.
 
<gallery>
 
Image:Debug_Startup_Options_01.png
 
</gallery>
 
  
Now, try the Run test ! The first time in a debugging session, expect a warning and then a logon box where you need put in your password as the debugger starts up. Annoying but its all fine after that.
+
=== Step 4: Install the Lazarus IDE ===
  
For authorative/more detailed instructions for FPC, please go to [http://freepascal.stack.nl/down/i386/macosx-netherlands.html]
+
{{Note| For installation on Apple Silicon/AArch64, please refer to the [[#Lazarus Fixes 2.2|Lazarus Fixes 2.2]] or [[#Lazarus Trunk|Lazarus Trunk]] instructions to build a native Lazarus IDE. Skip to the building instructions and use the Lazarus Fixes 2.2 source / Lazarus Trunk source download as you wish.}}
  
== Compatibility ==
+
Download and install the Lazarus IDE from the [https://sourceforge.net/projects/lazarus/files/ Lazarus IDE file area]. When you arrive at that file area, choose the correct version of your operating system. The vast majority of Mac users should now choose the 64 bit packages in the Lazarus macOS x86-64 directory. Every Mac computer since late 2006 has been 64 bit capable. The fact that Apple has completely dropped all 32 bit support from macOS 10.15 Catalina (released in October 2019) is another reason to choose the 64 bit packages.
Not every combination of Lazarus and Free Pascal is compatible with every installation of Mac OS X. Please refer to the following table in order to find the correct version for your development environment:
 
{{Template:Compatibility matrix of Lazarus for Mac}}
 
  
== Carbon and Cocoa ==
+
=== Step 5: Configure the Debugger ===
At present (late 2017) Lazarus using Carbon is a pretty good experience, things work pretty much as expected. However, it must be remembered that Carbon is intentionally limited (by Apple) to 32 bits and there is every reason to believe it might be dropped altogether in a later release of OSX. The alternatives include Cocoa, QT and GTK2+. The latter two require additional libraries and GTK2+ on the Mac appears to get little attention these days. QT on the Mac does have some strong supporters on the forum.
 
  
However, Cocoa is generally recognized as the future. Its possible to build an all Cocoa version of Lazarus but at time of writing, it does not look very usable. Its also possible to make a Cocoa install and use that at the command line to compile an existing project, probably put together in a Carbon based Lazarus. Such a project will then be using the Cocoa widget set and could be 64bit.
+
In versions of Lazarus 1.8.4 and earlier, you needed to use gdb as a debugger, slow to install and hard to sign. Since Lazarus 2.0.0 you can (and should) use lldb, a debugger provided by Apple, no signing required.
  
A good tutorial is available at https://macpgmr.github.io/MacXPlatform/UsingCocoaFromTrunk.html  Its specifically about using a particular Cocoa only Component but provides clear instructions that can be used generally.
+
Assuming you have installed what is necessary and started Lazarus, all that remains is configuring the debugger. If you don't do this now, Lazarus will try to use gdb and fail.
  
== Download the sources via svn ==
+
First, click Tools > Options > Debugger. Top right of the window now open has a label, "Debugger type and path", you must set both. Select "LLDB debugger (with fpdebug) (Beta)".
  
*Note: '''IF''' the current SVN of FreePascal can not be compiled using the stable release of FreePascal that comes with the current stable version of Lazarus (FPC 2.6.*), you will need a newer compiler. In order to compile the latest versions of FPC, first install a precompiled 2.6.* series compiler. You can get a compiled version of FPC 2.6.* at http://www.freepascal.org/download.var. '''Note''': only do this if the instructions below do not work.
+
[[File:Set_Debugger2.png|none]]
  
The sources are kept in a version control system called subversion or short '''svn''':
+
If it is not shown in the selection list, see [[#Installing_LazDebuggerFpLLdb|Installing LazDebuggerFpLLdb]] below. The XCode command line tools install lldb to the <tt>/usr/bin</tt> directory. Save those settings and you can now try to compile the almost nothing program that Lazarus has kindly provided for you (click the small green triangle near top left).
  
*10.5 and higher already contains svn clients. Users of earlier versions must install SVN for Mac OS X. A good package is provided by [http://www.codingmonkeys.de/mbo/ Martin Ott]. You can also use fink. SVN clients with GUI (graphical user interface) are available from [http://www.versiontracker.com Versiontracker]. A quite handy client, which integrates in Finder, is [http://scplugin.tigris.org SCPlugin].
+
Next you see a puzzling question, see image below. Choose a "Debug Format" from one of the offered -
  
Create a directory, where you would like to put the sources. You don't need to be root to do this. Any normal user can do this.
+
[[File:Set_Dwarf.png|none]]
First create a directory for fpc
 
: (e.g. /Users/username/freepascal)
 
then open a terminal and do the following:
 
[]$ svn co http://svn.freepascal.org/svn/fpc/trunk fpc
 
This will create a directory called 'fpc', which can be later used in the IDE.
 
Hint: To download/update the latest changes you can simply do
 
[]$ cd /Users/username/freepascal/fpc
 
[]$ svn up
 
  
Building fpc
+
Martin_fr, the person who has given us this interface between Lazarus and lldb, suggests you use ''' "dwarf3" '''. Then, you need to enter your password, a macOS cuteness because one application appears to be interfering with another. In this case, that's fine!
[]$ make clean all
 
[]$ sudo make install
 
  
Then download lazarus
+
In the latest versions of Lazarus (tested on 2.1.0 compiled from source) click Lazarus > Preferences... > Debugger > Debugger backend. In the Debugger type and path box select "LLDB debugger (with fpdebug)(Beta) and /usr/bin/lldb. This requires that the package lazdebuggerfplldb.lpk has been installed for it to work as described below.
[]$ svn co http://svn.freepascal.org/svn/lazarus/trunk lazarus
 
This will create a directory called 'lazarus'.
 
To update the latest changes:
 
[]$ cd /Users/username/freepascal/lazarus
 
  []$ svn up
 
  
Building lazarus
+
When running the debugger from time to time you will be asked for your password to allow debugging. This is for your own safety.
[]$ make clean all
 
  
Then start lazarus either via command line or by double click in the finder:
+
==== Extra Information on using lldb ====
  open lazarus.app
 
  
== Download stable sources ==
+
A great deal of information about using lldb appears in [https://forum.lazarus.freepascal.org/index.php/topic,42869.0.html this forum thread]. Here are a few gems, again, from Martin_fr:
  
Source code of stable versions is available in the [http://sourceforge.net/projects/lazarus/files/Lazarus%20Zip%20_%20GZip/ Lazarus Zip - GZip] archives. This is e.g. an option for users, who want to run the latest official Lazarus versions on "unsupported" machines, e.g. PPC-based Macs. Provided that you have installed the latest stable FPC version together with sources, it is sufficient to download and unpack the zip archive. Move it to the desired location (e.g. your /Developer folder), open a terminal window and change the shell's path to this folder (the easiest way to do this is to type "cd " and then to drag the icon of the freshly unpacked Lazarus folder to the position after this command in the Terminal window). If necessary enter <return> and then
+
In the unexpected case of problems, it may be worth trying "dwarf with sets" instead of just "dwarf3".  
[]$ make clean bigide
 
  
and <return> again. Subsequently, Free Pascal will use the makefile in this folder to build the Lazarus IDE. This may take a few minutes, but the process is fully automated. Therefore, you might want to look for a cup of coffee, while FPC is working. If the compiler is ready it prints the number of processed lines and the required time to the shell's output.
+
The "debug info" setting only affects the units directly in your project. However, units in packages may have debug info too. This can be:
  
The last step is to right-klick on the Lazarus bundle icon and to select "Show Package Contents" from the context menu. Then drag the executable "lazarus" to the folder "Contents/MacOS" of the bundle. That's it.
+
* set per package
 +
* for many, but not all packages in the menu Tools > Configure "Build Lazarus"
 +
* Project > Project Options > [[IDE_Window:_Compiler_Options#Additions_and_Overrides|Additions and Overrides]]
  
= Legacy Information =
+
If you change settings for a package, you might want to check which package you expect to step into when debugging. Packages you do not step into, do not need debug info.
  
=== XCode Compatability ===
+
If you use a type from a package (such as TForm from LCL) it is enough that your unit (in which you declare the variable / must declare and use a variable to include the type) has debug info. Reducing the number of packages with debug info (including those that default to have debug info), can shorten the debuggers start-up time.
Information relating to older versions of FPC, Lazarus and Apple Developer Tools
 
  
==== Compatibility with Xcode 5.0 and newer versions (Mac OS X 10.8, 10.9, 10.10 and 10.11) ====
+
Also it may be worth comparing (it has not been tested) the debuggers start up time for the same settings, only changing the checkbox "use external debug info".
Like Xcode 4.3+, Xcode 5 and subsequent versions no longer install the command line tools by default. These are required by FPC/Lazarus, however. Unlike in Xcode 4 the installation option is no longer accessible in Xcode 5 via the Downloads tab. Additionally, the "Locations" tab of the preferences dialog may be confusing, as it mentions that the command line tools are installed:
 
  
<gallery>
+
This needs to be only set in your project. If set in your project it will affect all packages. (If set in a package it will do nothing / at least should...)
Image:xcode5 misleading screenshot.png|Default location of command line tools in Xcode 5.
 
Image:xcode select.png|Installation of command line tools with the xcode-select command part 1...
 
Image:command line tools installation on mavericks.png|...and part 2.
 
</gallery>
 
  
The first dialog box shows that by default the command line tools are only installed inside the Xcode.app bundle itself. To install them globally, as required by FPC/Lazarus, execute the following terminal command:
+
==== Installing LazDebuggerFpLLdb ====
<syntaxhighlight lang="bash">
 
xcode-select --install
 
</syntaxhighlight>
 
  
Depending from your Xcode version alternative steps to install the command line developer tools may be to download them directly in the Xcode preferences window (see screenshots above) or to download them from [http://developer.apple.com developer.apple.com] (please take care to install the command line tools that are correct exactly for your Xcode version).
+
If you installed from source and used the bigide parameter to make, then the correct debugger will be installed, as a package, and ready to go. If, however, you installed in another way, it may, or may not be there. From the main IDE screen, click Packages->Install/UninstallPackages. Shown is two lists of packages, the list on the left is installed, the list on the right is available to install. Look for LazDebuggerFpLldb (exactly that, there are some similar named but less suitable packages). If it is on the right hand side, click it, press "Install Selection" and then "Save and rebuild IDE". This will take a little time, the IDE will shutdown and restart and all should be well. Now jump back up the page and continue configuring the debugger.
  
*You can compile and install the normal gdb. See [[GDB on OS X Mavericks and Xcode 5]].
+
== Cocoa 64 bit vs Carbon 32 bit ==
  
==== Xcode 4.3+ compatibility (Mac OS X 10.7/10.8) ====
+
Lazarus using the Apple 64 bit Cocoa framework should now meet the needs of users. The Apple 32 bit Carbon framework works pretty much as expected but you are advised to try Cocoa first, because Apple has dropped support for 32 bit applications and the Carbon framework from macOS 10.15 Catalina which was released in October 2019.  
Xcode 4.3 and later no longer install the command line tools by default. These are required by FPC/Lazarus.  
 
  
To install them manually, open Xcode, go to Preferences, select "Downloads;" and install the "Command Line Tools". Afterwards, FPC will install and function correctly.
+
Alternatives include QT and GTK2+, both requiring additional libraries and GTK2+ on the Mac appears to get little attention these days. QT on the Mac does have some strong supporters on the [https://forum.lazarus.freepascal.org/index.php/board,22.0.html Lazarus forum].
  
<gallery>
+
'''Cocoa''' is now undeniably the future on the Mac. It is possible to build an all Cocoa version of Lazarus with release 2.0.0 and later.  It is also possible to make a Carbon install of Lazarus (unless you are running macOS 10.15 Catalina or later) and use that to generate Cocoa 64 bit binaries.  
Image:install command line tools 1.png
 
Image:install command line tools 2.png
 
Image:install command line tools 3.png
 
</gallery>
 
  
It will be necessary to reinstall the command line tools after each upgrade of Xcode (especially when it's a new major version, the installer may delete the old copies of the command line tools), and also after switching to a new major version of the system software (idem). You may also download the command line tools from [https://developer.apple.com/download/more/?=command%20line%20tools Apple Developer].
+
In the Carbon or Cocoa IDE, you need to set the Target to the 64 bit processor and select the Cocoa Widget set:
  
==== Xcode 3.2.x compatibility (Mac OS X 10.6) ====
+
* Open your project with Lazarus and from the menu select Project > Project Options
FPC 2.6.0: there is an issue when compiling dynamic libraries with FPC under Mac OS X 10.6 due to a bug in the Xcode 3.2.x linker. This bug has been fixed in Xcode 4. You can work around the bug in Xcode 3.2.x by using the -k-no_order_inits command line parameter when compiling a dynamic library.
+
* In the "Config and Target" panel set the "Target CPU family" to be "x86_64"
 +
* In the "Additions and Overrides" panel click on "Set LCLWidgetType" pulldown and set the value to "Cocoa"
 +
* For some reason Lazarus sets the compiler to "/usr/local/bin/ppc386" - which results in 32 bit applications. Make sure under Tools > Options that "Compiler Executable" is set to "/usr/local/bin/fpc" to get 64 bit applications.
 +
* Now compile your project - and please feed back any problems you experience.
  
==== Xcode 3.1.x compatibility (Mac OS X 10.5) ====
+
== FPC + Lazarus Compatibility Matrix ==
Most versions of Lazarus and FPC are compatible with Xcode 3.1 (see the [[#Compatibility|compatibility]] matrix for detailed reference). The Xcode integration kit is provided as an optional install to allow for developing with Free Pascal directly from Xcode. It is not required for development with Lazarus, however.
 
  
==== Xcode 2.x compatibility (Mac OS X 10.4) ====
+
Not every combination of Lazarus and Free Pascal is compatible with every installation of macOS. Please refer to the following table in order to find the correct version for your development environment:
Most versions of Lazarus and FPC are compatible with Xcode 2.3 or newer (see the [[#Compatibility|compatibility]] matrix for detailled reference). The Xcode integration kit is provided as an optional install to allow for developing with Free Pascal directly from Xcode. It is not required for development with Lazarus, however. Xcode 2.0 was compatible with Lazarus 0.9.x, but it is no longer supported by newer versions of the Lazarus IDE.
+
{{Template:Compatibility matrix of Lazarus for Mac}}
  
== Install Packages / Released version ==
+
== Installing non-release versions of the Lazarus IDE ==
  
 +
=== Lazarus Fixes 2.2 ===
  
 +
* [[Lazarus_2.2_fixes_branch|Fixes included in fixes_2_2]]
  
=== Installation from disk images ===
+
There are a number of reasons why you may be better off using a non-release version of Lazarus, specifically, fixes_2_2. Particularly:
  
Download the three disk images (.dmg files) for fpc, fpcsrc and lazarus from either of the following links:
+
* You almost certainly need to target 64 bit Cocoa, macOS 10.15 Catalina and later do not support 32 bit Carbon at all.
 +
* The Cocoa widget set has steadily improved and the lldb debugger interface has rapidly improved, since even v2.0.0.
 +
* If your Mac has an Apple M1 Processor, the debugger in fixes_2_2 now works for aarch64.
 +
* Fixes_2_2 is a safer and more stable option than trunk, but still gets the new features much faster than the release version.
  
* [http://sourceforge.net/projects/lazarus/files/Lazarus%20Mac%20OS%20X%20i386/ Intel-based Macs]
+
Pre-compiled binaries based on fixes_2_2 are not available from SourceForge so we download and build from the source code. A little slow initially but very reliable and a great test of your compiler install ! You will need git which is included in all recent versions of the Xcode command line tools which you should have already installed (see [[#Step_2:_Xcode_Command_Line_Tools|Xcode Command Line Tools]] above).
* [http://sourceforge.net/projects/lazarus/files/Lazarus%20Mac%20OS%20X%20powerpc/ PowerPC-based Macs]
 
  
Open up each disk image and install in this order:
+
About svn or git: The Xcode 11.4 command line tools on macOS 10.15 no longer install svn, only git. You can install subversion via fink, ports or brew.
# fpc
 
# fpcsrc
 
# Lazarus
 
  
After installation the Lazarus application can be found in /Developer/lazarus/, the FPC source files in /usr/local/share/fpcsrc.
+
{{Apple Silicon Lazarus Build Notes}}
  
If you receive a "Can't find unit Interfaces used by Project1" error on trying to compile a blank form, check the following settings in Lazarus (should be set by default):
+
==== Downloading Lazarus Fixes 2.2 source ====
  
Environment Options
+
Create a directory for Lazarus and download the current fixes version:
  Lazarus directory: /Developer/lazarus
 
  Compiler path: /usr/local/bin/ppc386 (PowerPC Macs: /usr/local/bin/ppcppc)
 
  FPC Source: /usr/local/share/fpcsrc
 
  
Project | Options
+
<syntaxhighlight lang="bash">
  All paths blank
+
cd
  LCL Widget Type: default (Carbon beta)
+
mkdir -p bin/lazarus
 +
cd bin/lazarus
 +
</syntaxhighlight>
  
Project | Inspector
+
Using git:
  Required Packages
+
  git clone -b fixes_2_2 https://gitlab.com/freepascal.org/lazarus/lazarus.git laz_fixes
      LCL
 
   
 
Note - different versions of Lazarus depend on particular versions of the FreePascal compiler and will not work with other versions.
 
  
Another common problem is that the versions of fpc and fpcsrc are different.
+
Using svn:
 +
svn checkout https://github.com/fpc/Lazarus/branches/fixes_2_2 laz_fixes
  
This is the easiest way to install Lazarus on Mac OS X.
+
Depending on your internet connection and server congestion this takes a few seconds or a few minutes.
  
== Install from Source / Development version ==
+
==== Updating Lazarus Fixes 2.2 source ====
  
You need the latest stable released FPC installed in order to compile the development version.
+
To keep your fixes_2_2 installation up to date is as easy as:
  
=== Download and install a compiler ===
+
Using git:
  
Download and install the FPC package: https://sourceforge.net/project/showfiles.php?group_id=89339
+
<syntaxhighlight lang="bash">
 +
cd ~/bin/lazarus/laz_fixes
 +
git clean -f -d
 +
git pull
 +
</syntaxhighlight>
  
There are two development versions of the compiler: 2.6.x is stable version without new features - only bug fixes. The unstable version 2.7.x comes with lots of new features but sometimes also with bugs. Best is to download and install fpc 2.6.x. Some daily snapshots can be found [http://snapshots.lazarus.shikami.org/lazarus/ here]. Keep in mind that these are daily snapshots and that you can have bad luck and get a buggy version. The probability is about 1:30. So if the version is buggy try another day or use the released packages instead.
+
Using svn:
  
= Uninstalling Lazarus and Free Pascal =
+
<syntaxhighlight lang="bash">
 
+
cd ~/bin/lazarus/laz_fixes
== Installed using fink ==
+
svn clean --remove-unversioned
 +
svn update
 +
</syntaxhighlight>
  
The complete uninstall of all fpc and lazarus packages is done with:
+
==== Building Lazarus Fixes 2.2 source ====
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
fink purge --recursive fpc-config
+
cd laz_fixes
 +
make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
 +
//-wait some time...
 +
open startlazarus.app --args "--pcp=~/.laz_fixes"
 
</syntaxhighlight>
 
</syntaxhighlight>
  
If you want to preserve changes to the preference file /sw/etc/fpc.cfg, do:
+
* Note I pass a parameter to use a config directory that is based on the name of the actual install directory. It makes some scripting easy.
 +
 
 +
* On older macOS versions supporting 32 bit applications, replace the above make line with "''make LCL_PLATFORM=carbon CPU_TARGET=i386 bigide'' " and set up your project as mentioned in the [[#Cocoa_64_bit_vs_Carbon_32_bit|Carbon and Cocoa]] section below.
 +
 
 +
You might like to put a small script in your $HOME/bin directory and even set a path to it (very UNIX!)
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
fink remove --recursive fpc-config
+
#!/bin/bash
 +
LAZDIR="laz_fixes"
 +
cd ~/bin/lazarus/"$LAZDIR"
 +
open ~/bin/lazarus/"$LAZDIR"/lazarus.app --args "--pcp=~/.$LAZDIR"
 
</syntaxhighlight>
 
</syntaxhighlight>
  
For the removal of the Lazarus preference folder and files in your home directory, see below ([[#Lazarus preference folder .lazarus in the home directory | Lazarus preference folder]]).
+
=== Lazarus Trunk ===
  
== Installed from disk images or sources ==
+
Precompiled binaries based on the trunk development version of the Lazarus IDE are not available from SourceForge, so here's how to download the trunk source using svn or git and build the Lazarus IDE. You will need svn (before macOS 10.15 - Catalina) or git (after macOS 10.14 - Mojave) which is included in the Xcode command line tools which you should have already installed (see Xcode Command Line Tools above).
  
Normally you uninstall an application on OS X simply by dragging it from the Applications folder to the trash. But because Lazarus and Free Pascal are development tools, they're installed in several folders that you don't normally see in Finder.
+
{{Apple Silicon Lazarus Build Notes}}
  
You can copy and save the commands below to file uninstallLaz.sh and run it if you need to uninstall Lazarus and Free Pascal. You can usually install newer versions of Lazarus and Free Pascal over older versions, but as with most software it's not a bad idea to clean out everything before you install a newer version. This list of commands should also give you a sense of where the various pieces of Lazarus and Free Pascal are located.
+
==== Downloading Lazarus trunk source ====
  
<syntaxhighlight lang="bash">
+
<syntaxhighlight lang="sh">
bin=/usr/local/bin
+
cd
share=/usr/local/share
+
mkdir -p bin/lazarus
lib=/usr/local/lib
+
cd bin/lazarus
receipts=/Library/Receipts
+
</syntaxhighlight>
private=/private/etc
 
  
rm -fv $bin/ppcppc
+
Using git:
rm -fv $bin/ppc386
+
git clone -b main https://gitlab.com/freepascal.org/lazarus/lazarus.git laz_trunk
rm -fv $bin/bin2obj
 
rm -fv $bin/data2inc
 
rm -fv $bin/delp
 
rm -fv $bin/fd2pascal
 
rm -fv $bin/fpc
 
rm -fv $bin/fpcmake
 
rm -fv $bin/fpcmkcfg
 
rm -fv $bin/fpcsubst
 
rm -fv $bin/fpdoc
 
rm -fv $bin/fprcp
 
rm -fv $bin/h2pas
 
rm -fv $bin/h2paspp
 
rm -fv $bin/makeskel
 
rm -fv $bin/mkxmlrpc
 
rm -fv $bin/plex
 
rm -fv $bin/postw32
 
rm -fv $bin/ppdep
 
rm -fv $bin/ppudump
 
rm -fv $bin/ppufiles
 
rm -fv $bin/ppumove
 
rm -fv $bin/ptop
 
rm -fv $bin/pyacc
 
rm -fv $bin/rstconv
 
rm -fv $bin/unitdiff
 
rm -r $private/lazarus
 
rm -r $bin/lazarus
 
rm -r $share/lazarus
 
rm -r $share/fpcsrc
 
rm -r $share/doc/fpc-2.2.2
 
rm -r $share/examples/fpc-2.2.2
 
  
rm -r $lib/fpc
+
Using svn:
 +
svn checkout --depth files https://github.com/fpc/Lazarus/branches all
 +
cd all
 +
svn update --set-depth infinity main
  
rm -r $receipts/lazarus-*.pkg
+
The above svn above invocation is more complex due to a bug in many versions of Subversion. This workaround was the work of Alfred (aka Don Alfredo in the [[Forum]]) who is the wizard behind [[fpcupdeluxe]].
rm -r $receipts/fpcsrc-*.pkg
 
rm -r $receipts/fpc-*.pkg
 
  
rm -fv /etc/fpc.cfg
+
==== Updating Lazarus trunk source ====
</syntaxhighlight>
 
  
Note that this assumes you have version 2.2.2 snapshot of Free Pascal installed. If you have a different version, change the two relevant commands to specify your version.
+
To update your existing trunk source.
  
To run this script, change to the directory where it's stored and enter:
+
Using git:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
chmod +x uninstallLaz.sh
+
cd ~/bin/lazarus/laz_trunk
sudo ./uninstallLaz.sh
+
git clean -f -d
 +
git pull
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Then enter your password when prompted.
+
Using svn:
  
=== Lazarus preference folder .lazarus in the home directory ===
+
<syntaxhighlight lang="bash">
 +
cd ~/bin/lazarus/laz_trunk
 +
svn cleanup --remove-unversioned
 +
svn update
 +
</syntaxhighlight>
  
'''''Note:'''''  Lazarus also creates a .lazarus folder in your home directory where it stores environment settings and a list of recently opened projects and files. You can leave this folder alone if you want the new version of Lazarus you're installing to use your old settings. OS X normally doesn't show files or folders whose names start with a dot (.). To see this folder and its contents, enter the following in a terminal window:
+
==== Building Lazarus trunk source ====
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
cd ~/
+
make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
ls -al
+
//-wait some time...
cd .lazarus
+
open startlazarus.app --args "--pcp=~/.laz_trunk"
ls
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
To remove it, execute the following commands:
+
=== What does the bigide make argument do? ===
 +
 
 +
{{BigIDE}}
 +
 
 +
== Installing non-release versions of FPC ==
 +
 
 +
{{macOS FPC Source Installation}}
 +
 
 +
== Known issues and solutions ==
 +
 
 +
=== Lazarus IDE - Unable to "run without debugging" ===
 +
 
 +
<div class="mw-collapsible mw-collapsed">
 +
 
 +
If you are using the Lazarus IDE 2.0.10 and the ''Run > Run without debugging'' menu option fails with a dialog similar to:
 +
 
 +
<div class="mw-collapsible-content">
 +
 
 +
[[file:run_dialog_fail.png|350px]]
 +
 
 +
then you need to patch the Lazarus 2.0.10 source code ({{MantisLink|37324}} and {{MantisLink|36780}}). Specifically, patch <tt>../ide/main.pp</tt> as below (unpatched lines shown first, patched lines shown second):
 +
 
 +
  7243,7245c7243,7245
 +
  <    if RunAppBundle
 +
  <        and FileExistsUTF8(Process.Executable)
 +
  <    and FileExistsUTF8('/usr/bin/open') then
 +
  ---
 +
  >    if RunAppBundle then
 +
  >    //    and FileExistsUTF8(Process.Executable)
 +
  >    //and FileExistsUTF8('/usr/bin/open') then
 +
 
 +
and recompile the Lazarus IDE.
 +
 
 +
Alternatively, you can omit patching the source code and simply recompile Lazarus 2.0.10 with FPC 3.0.4.
 +
 
 +
A similar patching exercise and recompiling, or simply recompiling with FPC 3.0.4, needs to be done for Lazarus 2.0.8 if it has been compiled with FPC 3.2.0.
 +
</div></div>
 +
 
 +
=== Upgrading from Mojave (10.14) to Catalina (10.15) ===
 +
 
 +
<div class="mw-collapsible mw-collapsed">
 +
 
 +
* Run <code>sudo xcode-select --install</code>
 +
 
 +
<div class="mw-collapsible-content">
 +
 
 +
* To enable Lazarus to locate the <tt>crt1.10.5.o</tt> file change in <tt>/etc/fpc.cfg</tt> the -Fl behind "#ifdef cpux86_64" from
 +
-Fl/Applications/Xcode.app/Contents/Developer/Toolchain...
 +
to
 +
-Fl/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/
 +
</div></div>
 +
 
 +
=== Building the FPC compiler from Mojave (10.14) onwards ===
 +
 
 +
<div class="mw-collapsible mw-collapsed">
 +
 
 +
* To find the crt1.10.5.o file when building a later Free Pascal Compiler version from source, you need to specify:
 +
 
 +
<div class="mw-collapsible-content">
 +
 
 +
  OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
  
<syntaxhighlight lang="bash">
+
on the make command line because FPC ignores the <tt>/etc/fpc.cfg</tt> configuration file during builds of itself.
cd ~/
+
</div></div>
rm -rv .lazarus
 
</syntaxhighlight>
 
  
= Known issues =
+
=== Mac Installation FAQ ===
  
*FPC 2.4.4 has a bug. You can not compile the IDE with the range check flag '''-Cr'''.
+
* See the [[Mac Installation FAQ]] for solutions to other common problems that may arise during (and after) installation of Lazarus and Free Pascal on macOS.
*On OS X 10.4 you have to manually uninstall any previous version before installing a new dmg. Delete the following files and folders:
 
**/Developer/lazarus
 
**/Library/Receipts/lazarus.pkg
 
**/etc/lazarus
 
**/usr/local/bin/lazbuild
 
  
= See Also =
+
== Uninstalling Lazarus and Free Pascal ==
  
* [[Mac Installation FAQ]]
+
Refer to [[Uninstalling Lazarus on macOS]] for uninstallation options.
  
==Other Interfaces==
+
== Legacy Information ==
{{Interfaces}}
 
  
===Platform specific Tips===
+
See [[Legacy Information: Installing Lazarus on Mac|Legacy Information]] for details of:
*[[OS X Programming Tips]] - Lazarus installation, useful tools, Unix commands, and more...
 
*[[WinCE Programming Tips]] - Using the telephone API, sending SMSes, and more...
 
*[[Windows Programming Tips]] - Desktop Windows programming tips.
 
  
===Mac How To Articles===
+
* Installing Lazarus on Mac OS X 10.4 (Tiger), Mac OS X 10.5 (Leopard), OS X 10.8 (Mountain Lion)
* [http://www.mac-how.net Mac How] - If you having troubles in solving some major issues.
+
* Installing Lazarus 2.0.8, 2.0.10 with FPC 3.2.0 for macOS 10.10 and earlier
 +
* Installing Lazarus 2.0.8 with FPC 3.2.0 for macOS 10.11+
 +
* Installing Lazarus on PowerPC-based Macs
 +
* Old Xcode versions
 +
* Installing the gdb debugger
 +
* Compatibility matrix for Lazarus 1.0.0 through 1.6.4 and FPC 2.6.0 through 3.0.2.
  
===Interfaces Development Articles===
+
== See also ==
*[[Carbon interface internals]] - If you want to help improving the Carbon interface
 
*[[Windows CE Development Notes]] - For Pocket PC and Smartphones
 
*[[Adding a new interface]] - How to add a new widget set interface
 
*[[LCL Defines]] - Choosing the right options to recompile LCL
 
*[[LCL Internals]] - Some info about the inner workings of the LCL
 
  
[[Category:Mac OS X]]
+
* [[Xcode]].
[[Category:Install]]
+
* [[Other macOS installation options]].
[[Category:Lazarus]]
+
* [[Multiple Lazarus|Installing multiple Lazarus versions]].
 +
* [[Portal:Mac|Mac Portal]] for an overview of development for macOS with Lazarus and Free Pascal.
 +
* [[Mac Installation FAQ]] for solutions to the most frequent problems that may arise during (and after) installation of Lazarus and Free Pascal on macOS.
 +
* [[Lazarus_2.2.0_release_notes|Lazarus Trunk Notes]] - Note: work in progress
 +
* [[Lazarus 2.0 fixes branch|Lazarus 2.0 Fixes Branch Notes]] - Note: work in progress

Latest revision as of 09:37, 18 August 2021

English (en) 한국어 (ko) русский (ru)

macOSlogo.png

This article applies to macOS only.

See also: Multiplatform Programming Guide


Installing Lazarus on a Mac is not particularly difficult but it is critical that you do the install in the correct order. Skipping steps will almost certainly end in tears. In brief, here is what you need to do:

  1. Download and install Xcode (optional depending on your needs - see below for details).
  2. Install the global command line tools for Xcode.
  3. Download and install the Free Pascal Compiler (FPC) binaries and the FPC source from the Lazarus IDE file area (Important do this before you install the Lazarus IDE)
  4. Download and install the Lazarus IDE from the Lazarus IDE file area
  5. Configure LLDB - the Apple supplied (and signed) debugger from within the Lazarus IDE.

These steps are explained in more detail below.


Installation

The detailed instructions assume a recent version of macOS on your Mac, a recent version of Xcode from Apple and a recent version of Lazarus. On the Legacy Information page, you will see older information that may be relevant if you are using older components. You can assist by replacing out of date information, either deleting it, or, if it may help someone working with a legacy project, moving it to the legacy information page.

In general, this is about using both the Carbon and Cocoa Widget Sets. While Carbon was once seen as a little more stable, with the release Lazarus 2.0.8 the 64 bit Cocoa Widget Set has now surpassed Carbon and should be considered seriously for any new projects. Carbon was intentionally limited to 32 bits by Apple and you should be aware that it and the ability to run 32 bit executables have been removed completely from macOS 10.15 Catalina and later versions which now only support 64 bit executables using Cocoa.

Step 1: Download Xcode (optional)

Xcode is a 12GB download which will take up 16GB of disk space. You only need to download and install the full Xcode development environment if you need:

  • the SDKs for iOS, iPadOS, watchOS and tvOS; or
  • to validate and upload apps to the Mac App Store; or
  • to notarise apps for distribution outside of the Mac App Store.

Xcode 11.3.1 for use on macOS 10.14 Mojave must now be installed by downloading it from Apple Developer Connection (ADC), which requires free registration. Xcode 12.4.x for use on macOS 10.15 Catalina and macOS 11 Big Sur can be installed from the Mac App store. Note that you must first move any old Xcode versions from the Applications folder into the trash or rename the Xcode app (eg Xcode.app to Xcode_1014.app). You can then select which version of Xcode to use with the command line utility xcode-select. Open an Applications > Utilities > Terminal and type man xcode-select for this utility's manual page.

Older systems:

The Xcode developer tools can be installed from the original macOS installation disks or a newer copy downloaded from the Apple Developer Connection (ADC), which requires free registration. Download the Xcode file, it will end up in your Downloads directory as a zip file. Click it. It is unarchived into your Downloads directory. You may be happy with it there but maybe not. Other users will see the path to it but be unable to use it. And it is untidy there. So I moved mine and then told xcode-select where it was moved to (in a terminal) -

mv Downloads/Xcode.app /Developer/.
sudo xcode-select -s /Developer/Xcode.app/Contents/Developer

Step 2: Xcode Command Line Tools

This is shown here as a separate step because it really is a separate step. Don't confuse these standalone command line tools with the internal Xcode command line tools that the Xcode GUI will tell you are already installed if you installed the full Xcode package in Step 1. FPC cannot use those Xcode internal command line tools without configuration changes (see Xcode for details).

Do the following, it is quick and easy for all macOS versions up to and including Catalina 10.15:

sudo xcode-select --install
sudo xcodebuild -license accept

For Big Sur 11.x, you only need to enter the first of the two commands above unless you have also installed the full Xcode package. If you have only installed the command line tools, you should omit entering the xcodebuild command.

If you have problems installing the command line tools using this command line method (eg the installer freezes while "finding Software"), you can also download and install the command line tools package by logging in to the Apple Developer Site and downloading and installing the Command Line Tools for Xcode disk image.

Step 3: FPC binaries and FPC source code

Note-icon.png

Note: For installation on Apple Silicon/AArch64, after installing the 64 bit Intel binary and source for FPC, please refer to these instructions for building a native Apple Silicon Free Pascal Compiler.

Download and install the Free Pascal Compiler (FPC) binaries and the separate source package. A compatible FPC (and source) must be installed before you install Lazarus. You have a number of options.

Source Forge (Official Repository)

Download the official Free Pascal Compiler (FPC) binaries and FPC source packages from the Lazarus IDE file area.

When you arrive at that file area:

  1. Choose the correct version of your operating system. The vast majority of Mac users should now choose the 64 bit packages in the Lazarus macOS x86-64 directory. Every Mac computer since late 2006 has been 64 bit capable. The fact that Apple has completely dropped all 32 bit support from macOS 10.15 Catalina (released in October 2019) is another reason to choose the 64 bit packages.
  2. Choose the version of Lazarus you wish to install and you will be presented with the FPC binary and source packages to download.

These installation packages are built by the FPC/Lazarus developers and track formal releases. As these installation packages are not approved by Apple, you need to hold down the Control key, click the package and choose Open and confirm you want to install from an Unknown Developer.

You might like to try a simple and quick test of FPC at this stage - Testing FPC installation.

Step 4: Install the Lazarus IDE

Note-icon.png

Note: For installation on Apple Silicon/AArch64, please refer to the Lazarus Fixes 2.2 or Lazarus Trunk instructions to build a native Lazarus IDE. Skip to the building instructions and use the Lazarus Fixes 2.2 source / Lazarus Trunk source download as you wish.

Download and install the Lazarus IDE from the Lazarus IDE file area. When you arrive at that file area, choose the correct version of your operating system. The vast majority of Mac users should now choose the 64 bit packages in the Lazarus macOS x86-64 directory. Every Mac computer since late 2006 has been 64 bit capable. The fact that Apple has completely dropped all 32 bit support from macOS 10.15 Catalina (released in October 2019) is another reason to choose the 64 bit packages.

Step 5: Configure the Debugger

In versions of Lazarus 1.8.4 and earlier, you needed to use gdb as a debugger, slow to install and hard to sign. Since Lazarus 2.0.0 you can (and should) use lldb, a debugger provided by Apple, no signing required.

Assuming you have installed what is necessary and started Lazarus, all that remains is configuring the debugger. If you don't do this now, Lazarus will try to use gdb and fail.

First, click Tools > Options > Debugger. Top right of the window now open has a label, "Debugger type and path", you must set both. Select "LLDB debugger (with fpdebug) (Beta)".

Set Debugger2.png

If it is not shown in the selection list, see Installing LazDebuggerFpLLdb below. The XCode command line tools install lldb to the /usr/bin directory. Save those settings and you can now try to compile the almost nothing program that Lazarus has kindly provided for you (click the small green triangle near top left).

Next you see a puzzling question, see image below. Choose a "Debug Format" from one of the offered -

Set Dwarf.png

Martin_fr, the person who has given us this interface between Lazarus and lldb, suggests you use "dwarf3" . Then, you need to enter your password, a macOS cuteness because one application appears to be interfering with another. In this case, that's fine!

In the latest versions of Lazarus (tested on 2.1.0 compiled from source) click Lazarus > Preferences... > Debugger > Debugger backend. In the Debugger type and path box select "LLDB debugger (with fpdebug)(Beta) and /usr/bin/lldb. This requires that the package lazdebuggerfplldb.lpk has been installed for it to work as described below.

When running the debugger from time to time you will be asked for your password to allow debugging. This is for your own safety.

Extra Information on using lldb

A great deal of information about using lldb appears in this forum thread. Here are a few gems, again, from Martin_fr:

In the unexpected case of problems, it may be worth trying "dwarf with sets" instead of just "dwarf3".

The "debug info" setting only affects the units directly in your project. However, units in packages may have debug info too. This can be:

  • set per package
  • for many, but not all packages in the menu Tools > Configure "Build Lazarus"
  • Project > Project Options > Additions and Overrides

If you change settings for a package, you might want to check which package you expect to step into when debugging. Packages you do not step into, do not need debug info.

If you use a type from a package (such as TForm from LCL) it is enough that your unit (in which you declare the variable / must declare and use a variable to include the type) has debug info. Reducing the number of packages with debug info (including those that default to have debug info), can shorten the debuggers start-up time.

Also it may be worth comparing (it has not been tested) the debuggers start up time for the same settings, only changing the checkbox "use external debug info".

This needs to be only set in your project. If set in your project it will affect all packages. (If set in a package it will do nothing / at least should...)

Installing LazDebuggerFpLLdb

If you installed from source and used the bigide parameter to make, then the correct debugger will be installed, as a package, and ready to go. If, however, you installed in another way, it may, or may not be there. From the main IDE screen, click Packages->Install/UninstallPackages. Shown is two lists of packages, the list on the left is installed, the list on the right is available to install. Look for LazDebuggerFpLldb (exactly that, there are some similar named but less suitable packages). If it is on the right hand side, click it, press "Install Selection" and then "Save and rebuild IDE". This will take a little time, the IDE will shutdown and restart and all should be well. Now jump back up the page and continue configuring the debugger.

Cocoa 64 bit vs Carbon 32 bit

Lazarus using the Apple 64 bit Cocoa framework should now meet the needs of users. The Apple 32 bit Carbon framework works pretty much as expected but you are advised to try Cocoa first, because Apple has dropped support for 32 bit applications and the Carbon framework from macOS 10.15 Catalina which was released in October 2019.

Alternatives include QT and GTK2+, both requiring additional libraries and GTK2+ on the Mac appears to get little attention these days. QT on the Mac does have some strong supporters on the Lazarus forum.

Cocoa is now undeniably the future on the Mac. It is possible to build an all Cocoa version of Lazarus with release 2.0.0 and later. It is also possible to make a Carbon install of Lazarus (unless you are running macOS 10.15 Catalina or later) and use that to generate Cocoa 64 bit binaries.

In the Carbon or Cocoa IDE, you need to set the Target to the 64 bit processor and select the Cocoa Widget set:

  • Open your project with Lazarus and from the menu select Project > Project Options
  • In the "Config and Target" panel set the "Target CPU family" to be "x86_64"
  • In the "Additions and Overrides" panel click on "Set LCLWidgetType" pulldown and set the value to "Cocoa"
  • For some reason Lazarus sets the compiler to "/usr/local/bin/ppc386" - which results in 32 bit applications. Make sure under Tools > Options that "Compiler Executable" is set to "/usr/local/bin/fpc" to get 64 bit applications.
  • Now compile your project - and please feed back any problems you experience.

FPC + Lazarus Compatibility Matrix

Not every combination of Lazarus and Free Pascal is compatible with every installation of macOS. Please refer to the following table in order to find the correct version for your development environment:

Lazarus Compatibility Matrix
Lazarus 1.8.x Lazarus 2.0.y Lazarus 2.2.0 RC1
FPC 3.0.4 FPC 3.2.0 FPC 3.2.2
PPC processors
Mac OS X 10.4 (Tiger) Incompatible Incompatible Incompatible Incompatible Incompatible Incompatible Incompatible
Mac OS X 10.5 (Leopard) Not tested Not tested Incompatible Incompatible Incompatible Incompatible Incompatible
Intel processors
Mac OS X 10.4 (Tiger) Incompatible Incompatible Incompatible Incompatible Incompatible Incompatible Incompatible
Mac OS X 10.5 (Leopard) Not tested Compatible^ Not tested Compatible^**† Not tested Not tested Not tested
Mac OS X 10.6 (Snow Leopard) Compatible Compatible^^ Not tested Not tested Not tested Not tested Not tested
Mac OS X 10.7 (Lion) Compatible Not tested Not tested Not tested Not tested Not tested Not tested
OS X 10.8 (Mountain Lion) Compatible^^ Compatible Compatible**# Compatible**# Not tested Not tested Not tested
OS X 10.9 (Mavericks) Compatible^^ Compatible Compatible**† Compatible**† Not tested Not tested Not tested
OS X 10.10 (Yosemite) Compatible^^ Compatible Compatible**† Compatible**† Not tested Not tested Not tested
OS X 10.11 (El Capitan) Compatible^^ Compatible Compatible***† Compatible† Compatible## Not tested Not tested
macOS 10.12 (Sierra) Compatible^^ Compatible Compatible***† Compatible† Compatible† Compatible† Not tested
macOS 10.13 (High Sierra) Not tested Compatible Compatible***† Compatible† Compatible† Compatible† Not tested
macOS 10.14 (Mojave) Not tested Compatible Compatible***† Compatible† Compatible† Compatible† Compatible
macOS 10.15 (Catalina) Not tested Compatible Compatible***† Compatible† Compatible† Compatible† Compatible
macOS 11.0 (Big Sur) Not tested Compatible Compatible***† Compatible† Compatible† Compatible† Compatible
macOS 12.0 (Monterey Beta) Not tested Not tested Not tested Not tested Not tested Not tested Compatible
Apple Silicon processors
macOS 11.0 (Big Sur) Not tested Not tested Not tested Compatible†† Compatible†† Compatible††† Compatible*

x = 0, 2 or 4; y = 0, 2, 4, 6, 8, 10 or 12

^ Carbon interface compiles - Cocoa does not.

^^ Restrictions apply to debugging with gdb.

** See Installing Lazarus 2.0.8, 2.0.10 with FPC 3.2.0 for macOS 10.10 and earlier for instructions.

*** See Installing Lazarus 2.0.8 with FPC 3.2.0 for macOS 10.11+ for instructions.

# Cannot run with/without debugging in the IDE. Can run compiled application outside of the IDE. See Issue #37324

## You need to compile FPC 3.2.0 from source with FPC 3.0.4 which is installed with the Lazarus 2.0.12 packages.

† Cannot "run without debugging" in the IDE. Can run compiled application outside of the IDE. See Lazarus IDE - Unable to "run without debugging" for workaround. See Issue #36780.

†† You need to compile a native aarch64 version of FPC 3.3.1 (trunk) and Lazarus 2.0.12 from source to support an Apple Silicon M1 processor. Refer to these instructions for FPC and these instructions for the Lazarus IDE.

††† After installing FPC 3.2.2, you need to compile a native aarch64 version of Lazarus from source to support an Apple Silicon M1 processor. Refer to these instructions for compiling the Lazarus IDE.

* Lazarus 2.2 Release Candidate 1 installs universal binaries for FPC 3.2.2, but an Intel Lazarus IDE binary which you can use or recompile the IDE from within itself for a native aarch64 version. This may change when Lazarus 2.2 is officially released.

Installing non-release versions of the Lazarus IDE

Lazarus Fixes 2.2

There are a number of reasons why you may be better off using a non-release version of Lazarus, specifically, fixes_2_2. Particularly:

  • You almost certainly need to target 64 bit Cocoa, macOS 10.15 Catalina and later do not support 32 bit Carbon at all.
  • The Cocoa widget set has steadily improved and the lldb debugger interface has rapidly improved, since even v2.0.0.
  • If your Mac has an Apple M1 Processor, the debugger in fixes_2_2 now works for aarch64.
  • Fixes_2_2 is a safer and more stable option than trunk, but still gets the new features much faster than the release version.

Pre-compiled binaries based on fixes_2_2 are not available from SourceForge so we download and build from the source code. A little slow initially but very reliable and a great test of your compiler install ! You will need git which is included in all recent versions of the Xcode command line tools which you should have already installed (see Xcode Command Line Tools above).

About svn or git: The Xcode 11.4 command line tools on macOS 10.15 no longer install svn, only git. You can install subversion via fink, ports or brew.

Additional notes for building a native aarch64 Lazarus IDE for an Apple Silicon M1 processor Mac

  • Ensure you have compiled a native aarch64 Free Pascal Compiler (see Apple Silicon Support for how to do this).
Note-icon.png

Note: The FPC 3.2.2 release includes universal binaries which will run natively on both aarch64 (ARM 64 bit - Apple Silicon M1) as well as x86_64 (Intel 64 bit) so you no longer need to compile your own from source.

  • When building the Lazarus IDE, change the CPU_TARGET in the instructions below from x86_64 (Intel 64 bit) to aarch64 (ARM 64 bit - Apple Silicon M1).

Downloading Lazarus Fixes 2.2 source

Create a directory for Lazarus and download the current fixes version:

cd
mkdir -p bin/lazarus
cd bin/lazarus

Using git:

git clone -b fixes_2_2 https://gitlab.com/freepascal.org/lazarus/lazarus.git laz_fixes

Using svn:

svn checkout https://github.com/fpc/Lazarus/branches/fixes_2_2 laz_fixes

Depending on your internet connection and server congestion this takes a few seconds or a few minutes.

Updating Lazarus Fixes 2.2 source

To keep your fixes_2_2 installation up to date is as easy as:

Using git:

cd ~/bin/lazarus/laz_fixes
git clean -f -d
git pull

Using svn:

cd ~/bin/lazarus/laz_fixes
svn clean --remove-unversioned
svn update

Building Lazarus Fixes 2.2 source

cd laz_fixes
make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
//-wait some time...
open startlazarus.app --args "--pcp=~/.laz_fixes"
  • Note I pass a parameter to use a config directory that is based on the name of the actual install directory. It makes some scripting easy.
  • On older macOS versions supporting 32 bit applications, replace the above make line with "make LCL_PLATFORM=carbon CPU_TARGET=i386 bigide " and set up your project as mentioned in the Carbon and Cocoa section below.

You might like to put a small script in your $HOME/bin directory and even set a path to it (very UNIX!)

#!/bin/bash
LAZDIR="laz_fixes"
cd ~/bin/lazarus/"$LAZDIR"
open ~/bin/lazarus/"$LAZDIR"/lazarus.app --args "--pcp=~/.$LAZDIR"

Lazarus Trunk

Precompiled binaries based on the trunk development version of the Lazarus IDE are not available from SourceForge, so here's how to download the trunk source using svn or git and build the Lazarus IDE. You will need svn (before macOS 10.15 - Catalina) or git (after macOS 10.14 - Mojave) which is included in the Xcode command line tools which you should have already installed (see Xcode Command Line Tools above).

Additional notes for building a native aarch64 Lazarus IDE for an Apple Silicon M1 processor Mac

  • Ensure you have compiled a native aarch64 Free Pascal Compiler (see Apple Silicon Support for how to do this).
Note-icon.png

Note: The FPC 3.2.2 release includes universal binaries which will run natively on both aarch64 (ARM 64 bit - Apple Silicon M1) as well as x86_64 (Intel 64 bit) so you no longer need to compile your own from source.

  • When building the Lazarus IDE, change the CPU_TARGET in the instructions below from x86_64 (Intel 64 bit) to aarch64 (ARM 64 bit - Apple Silicon M1).

Downloading Lazarus trunk source

cd
mkdir -p bin/lazarus
cd bin/lazarus

Using git:

git clone -b main https://gitlab.com/freepascal.org/lazarus/lazarus.git laz_trunk

Using svn:

svn checkout --depth files https://github.com/fpc/Lazarus/branches all
cd all
svn update --set-depth infinity main

The above svn above invocation is more complex due to a bug in many versions of Subversion. This workaround was the work of Alfred (aka Don Alfredo in the Forum) who is the wizard behind fpcupdeluxe.

Updating Lazarus trunk source

To update your existing trunk source.

Using git:

cd ~/bin/lazarus/laz_trunk
git clean -f -d
git pull

Using svn:

cd ~/bin/lazarus/laz_trunk
svn cleanup --remove-unversioned
svn update

Building Lazarus trunk source

make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
//-wait some time...
open startlazarus.app --args "--pcp=~/.laz_trunk"

What does the bigide make argument do?

The bigide make argument adds a bunch of packages to Lazarus that many find useful and cannot do without. The packages that are added are:

  • cairocanvas
  • chmhelp
  • datetimectrls
  • externhelp
  • fpcunit
  • fpdebug
  • instantfpc
  • jcf2
  • lazcontrols
  • lazdebuggers
  • lclextensions
  • leakview
  • macroscript
  • memds
  • onlinepackagemanager
  • pas2js
  • PascalScript
  • printers
  • projecttemplates
  • rtticontrols
  • sdf
  • sqldb
  • synedit
  • tachart
  • tdbf
  • todolist
  • turbopower_ipro
  • virtualtreeview

The above list is sourced from the [Lazarus source directory]/IDE/Makefile.fpc and may be subject to change.

Note that if you have not compiled your own Lazarus IDE with the bigide argument, you can install any of these packages yourself using the Lazarus IDE Package > Install/Uninstall Packages... dialog.

Installing non-release versions of FPC

Installing from source

There are two current non-release branches of the Free Pascal Compiler: the development (trunk) branch and the Fixes 3.2 branch which includes additional fixes to the released 3.2.2 version. Developers, and those who like living on the bleeding edge and testing new features and fixes, will choose the development version; more normal users, who wish to use a stable branch with some additional fixes since the latest release version, will choose the Fixes branch. The instructions below cover both these branches.

The source code is kept in a version control system called git:

  • macOS 10.5 and higher already contain a command line git client if you have installed the Xcode command line utilities.
  • You also need the latest released Free Pascal Compiler version (3.2.2 as of August 2021) installed in order to be able to successfully compile the development (trunk) version.
Note-icon.png

Note: When building a native aarch64 Free Pascal Compiler (ppca64) for an Apple Silicon M1 processor Mac, change the CPU_TARGET in the instructions below from x86_64 (Intel 64 bit) to aarch64 (ARM 64 bit - Apple Silicon M1) and change any reference to ppcx64 to ppca64

FPC Trunk

Note that since FPC trunk is by definition still under development, some of the features may still change before they end up in a release version.

Create a directory where you would like to put the source (eg fpc_trunk in your home directory). You don't need to be root to do this. Any normal user can do this. Open an Applications > Utilities > Terminal and do the following:

 []$ git clone -b main https://gitlab.com/freepascal.org/fpc/source.git fpc_trunk

This will create a directory called 'fpc_trunk' and download the FPC trunk source to it.

To subsequently update your local source repository with the latest source changes you can simply do:

 []$ cd fpc
 []$ git clean -f -d
 []$ git pull

To build and install FPC (the highlighted text should be all on one line):

 []$ cd
 []$ cd fpc
 []$ make distclean all FPC=/usr/local/lib/fpc/3.2.2/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 []$ sudo make install OS_TARGET=darwin CPU_TARGET=x86_64

You will also need to update the links for the compiler in /usr/local/bin which will be pointing to the previous FPC version. For example:

 []$ cd /usr/local/bin
 []$ sudo rm ppc386
 []$ sudo rm ppcx64
 []$ sudo ln -s /usr/local/lib/fpc/3.3.1/ppc386
 []$ sudo ln -s /usr/local/lib/fpc/3.3.1/ppcx64

Note that you will need to build a new ppc386 compiler if you want to continue to compile 32 bit applications by replacing these lines (this may not be possible after Xcode 11.3.1 and macOS 10.14.6 Mojave because of Apple's removal of 32 bit frameworks):

 []$ make clean all FPC=/usr/local/lib/fpc/3.2.2/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 []$ sudo make install OS_TARGET=darwin CPU_TARGET=x86_64

with these two lines:

 []$ make clean all FPC=/usr/local/lib/fpc/3.2.2/ppc386 OS_TARGET=darwin CPU_TARGET=i386 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 []$ sudo make install OS_TARGET=darwin CPU_TARGET=i386

FPC Fixes 3.2

Create a directory where you would like to put the source (eg fpc_fixes32 in your home directory). You don't need to be root to do this. Any normal user can do this. Open an Applications > Utilities > Terminal and do the following:

 []$ git clone -b fixes_3_2 https://gitlab.com/freepascal.org/fpc/source.git fpc_fixes32

This will create a directory called fpc_fixes32 and download the FPC source to it.

To subsequently update your local copy of the repository source with the latest source changes you can simply do:

 []$ cd fpc_fixes32
 []$ git clean -f -d
 []$ git pull

To build and install FPC (the highlighted text should be all on one line):

 []$ cd
 []$ cd fpc_fixes32
 []$ make distclean all FPC=/usr/local/lib/fpc/3.2.2/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 []$ sudo make install OS_TARGET=darwin CPU_TARGET=x86_64

You will also need to update the links for the compiler in /usr/local/bin which will be pointing to the previous FPC version. For example:

 []$ cd /usr/local/bin
 []$ sudo rm ppc386
 []$ sudo rm ppcx64
 []$ sudo ln -s /usr/local/lib/fpc/fixes-3.2/ppc386
 []$ sudo ln -s /usr/local/lib/fpc/fixes-3.2/ppcx64

Note that you will need to build a new ppc386 compiler if you want to continue to compile 32 bit applications by replacing these lines (this may not be possible after Xcode 11.3.1 and macOS 10.14.6 Mojave because of Apple's removal of 32 bit frameworks):

 []$ make clean all FPC=/usr/local/lib/fpc/3.2.2/ppc386 OS_TARGET=darwin CPU_TARGET=i386 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 []$ sudo make install OS_TARGET=darwin CPU_TARGET=i386

Known issues and solutions

Lazarus IDE - Unable to "run without debugging"

If you are using the Lazarus IDE 2.0.10 and the Run > Run without debugging menu option fails with a dialog similar to:

run dialog fail.png

then you need to patch the Lazarus 2.0.10 source code (Issue #37324 and Issue #36780). Specifically, patch ../ide/main.pp as below (unpatched lines shown first, patched lines shown second):

 7243,7245c7243,7245
 <     if RunAppBundle
 <         and FileExistsUTF8(Process.Executable)
 <     and FileExistsUTF8('/usr/bin/open') then
 ---
 >     if RunAppBundle then
 >     //    and FileExistsUTF8(Process.Executable)
 >     //and FileExistsUTF8('/usr/bin/open') then

and recompile the Lazarus IDE.

Alternatively, you can omit patching the source code and simply recompile Lazarus 2.0.10 with FPC 3.0.4.

A similar patching exercise and recompiling, or simply recompiling with FPC 3.0.4, needs to be done for Lazarus 2.0.8 if it has been compiled with FPC 3.2.0.

Upgrading from Mojave (10.14) to Catalina (10.15)

  • Run sudo xcode-select --install
  • To enable Lazarus to locate the crt1.10.5.o file change in /etc/fpc.cfg the -Fl behind "#ifdef cpux86_64" from
-Fl/Applications/Xcode.app/Contents/Developer/Toolchain...

to

-Fl/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/

Building the FPC compiler from Mojave (10.14) onwards

  • To find the crt1.10.5.o file when building a later Free Pascal Compiler version from source, you need to specify:
 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"

on the make command line because FPC ignores the /etc/fpc.cfg configuration file during builds of itself.

Mac Installation FAQ

  • See the Mac Installation FAQ for solutions to other common problems that may arise during (and after) installation of Lazarus and Free Pascal on macOS.

Uninstalling Lazarus and Free Pascal

Refer to Uninstalling Lazarus on macOS for uninstallation options.

Legacy Information

See Legacy Information for details of:

  • Installing Lazarus on Mac OS X 10.4 (Tiger), Mac OS X 10.5 (Leopard), OS X 10.8 (Mountain Lion)
  • Installing Lazarus 2.0.8, 2.0.10 with FPC 3.2.0 for macOS 10.10 and earlier
  • Installing Lazarus 2.0.8 with FPC 3.2.0 for macOS 10.11+
  • Installing Lazarus on PowerPC-based Macs
  • Old Xcode versions
  • Installing the gdb debugger
  • Compatibility matrix for Lazarus 1.0.0 through 1.6.4 and FPC 2.6.0 through 3.0.2.

See also