Difference between revisions of "Installing Lazarus on macOS"

From Free Pascal wiki
Jump to navigationJump to search
m (→‎macOS 10.5 Leopard: Mention Xcode needs installing)
m (Fix typo)
(30 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Installing Lazarus on macOS}}
 
{{Installing Lazarus on macOS}}
 +
 +
{{Note| For installation on Apple Silicon/AArch64, please refer to [[macOS_Big_Sur_changes_for_developers#ARM64.2FAArch64.2FAppleSilicon_Support|Apple Silicon Support]].}}
  
 
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 lead to tears. In brief, here is what you need to 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 lead to tears. In brief, here is what you need to do:
Line 5: Line 7:
 
# Download and install Xcode.
 
# Download and install Xcode.
 
# Install the global command line tools for Xcode.
 
# Install the global command line tools for Xcode.
# Download and install Free Pascal Compiler and FPC Source from the [https://sourceforge.net/projects/lazarus/files/ Lazarus IDE file area] ('''Important''' do this ''before'' you install the Lazarus IDE)
+
# 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)
 
# Download and install the Lazarus IDE  from the [https://sourceforge.net/projects/lazarus/files/ Lazarus IDE file area]
 
# Download and install the Lazarus IDE  from the [https://sourceforge.net/projects/lazarus/files/ Lazarus IDE file area]
 
# Configure LLDB - the Apple supplied (and signed) debugger from within the Lazarus IDE.
 
# Configure LLDB - the Apple supplied (and signed) debugger from within the Lazarus IDE.
Line 25: Line 27:
 
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 11.4.x for use on macOS 10.15 Catalina 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 select which version of Xcode to use with the command line utility <tt>xcode-select</tt>.
 
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 11.4.x for use on macOS 10.15 Catalina 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 select which version of Xcode to use with the command line utility <tt>xcode-select</tt>.
  
Older systems:
+
'''Older systems:'''
  
 
The 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) -
 
The 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) -
Line 45: Line 47:
 
=== Step 3: FPC, FPC Source ===
 
=== Step 3: FPC, FPC Source ===
  
Download and install the Free Pascal Compiler (FPC) and source. A compatible FPC (and source) must be installed before you install Lazarus. You have a number of options.  
+
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 ====
 
==== Source Forge ====
  
Download the Free Pascal Compiler (FPC) and FPC source 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.
+
Download the Free Pascal Compiler (FPC) binaries and FPC source packages 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.
 
 
If you are choose to install FPC 3.2.0 rather than FPC 3.0.4, you will need to patch one line and recompile it before you can use it with Lazarus 2.0.8. See further [[##Installing_Lazarus_2.0.8_with_FPC_3.2.0|Known problems]] below.
 
  
 
These binary install kits are built by the FPC/Lazarus developers and track formal releases. 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.
 
These binary install kits are built by the FPC/Lazarus developers and track formal releases. 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.
Line 174: Line 174:
 
* Fixes_2_0 is a safer and more stable option than trunk, but still gets the new features much faster than the release version.
 
* Fixes_2_0 is a safer and more stable option than trunk, but still gets the new features much faster than the release version.
  
Precompiled binaries based on fixes_2_0 are not available from SourceForge but can be obtained from [[fpcupdeluxe]]. But here we will discuss downloading source and building. A little slow initially but very reliable and a great test of your compiler install ! You will need svn 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).
+
Precompiled binaries based on fixes_2_0 are not available from SourceForge but can be obtained from [[fpcupdeluxe]]. But here we will discuss downloading source and building. 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).
 +
 
 +
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.
 +
 
 +
Create a directory for Lazarus and download the current fixes version:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 180: Line 184:
 
mkdir -p bin/lazarus
 
mkdir -p bin/lazarus
 
cd bin/lazarus
 
cd bin/lazarus
svn checkout https://svn.freepascal.org/svn/lazarus/branches/fixes_2_0 laz_fixes
+
</syntaxhighlight>
//-wait some time...
+
 
 +
Using git:
 +
git clone -b fixes_2_0 https://github.com/User4martin/lazarus.git laz_fixes
 +
 
 +
Using svn:
 +
svn checkout https://svn.freepascal.org/svn/lazarus/branches/fixes_2_0 laz_fixes
 +
 
 +
Depending on your internet connection and server congestion this takes a few seconds or a couple of minutes. Then build it:
 +
 
 +
<syntaxhighlight lang="bash">
 
cd laz_fixes
 
cd laz_fixes
 
make LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
 
make LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
Line 190: Line 203:
 
* 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.
 
* 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.
  
* It is also quite feasible (and perhaps a touch safer) to build a 32 bit Carbon Lazarus IDE and use it to build 64 bit Cocoa applications unless you are running macOS 10.15 Catalina which has removed support for 32 bit Carbon. Replace above make line with "''make LCL_PLATFORM=carbon CPU_TARGET=i386 bigide'' " and setup your project as mentioned in the [[#Cocoa_64_bit_vs_Carbon_32_bit|Carbon and Cocoa]] section below.
+
* On older macOS supporting 32bit applications, replace above make line with "''make LCL_PLATFORM=carbon CPU_TARGET=i386 bigide'' " and setup 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!)
 
You might like to put a small script in your $HOME/bin directory and even set a path to it (very UNIX!)
Line 202: Line 215:
  
 
To keep your fixes_2_0 installation up to date is as easy as:
 
To keep your fixes_2_0 installation up to date is as easy as:
 +
 +
Using git:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
cd ~/bin/lazarus/laz_fixes
 
cd ~/bin/lazarus/laz_fixes
svn cleanup --remove-unversioned
+
git clean -f -d
 +
git pull
 +
//-wait a little time...
 +
make LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
 +
//-wait some time...
 +
open startlazarus.app --args "--pcp=~/.laz_fixes"
 +
</syntaxhighlight>
 +
 
 +
Using svn:
 +
 
 +
<syntaxhighlight lang="bash">
 +
cd ~/bin/lazarus/laz_fixes
 +
svn clean --remove-unversioned
 
svn update
 
svn update
 
//-wait a little time...
 
//-wait a little time...
Line 215: Line 242:
 
=== Lazarus Trunk ===
 
=== Lazarus Trunk ===
  
Precompiled binaries based on trunk are not available from SourceForge, so here's how to download the trunk source using svn and build the Lazarus IDE. You will need svn 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).
+
Precompiled binaries based on trunk are not available from SourceForge, so here's how to download the trunk source using git and build the Lazarus IDE. 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).
  
 
<syntaxhighlight lang="sh">
 
<syntaxhighlight lang="sh">
Line 221: Line 248:
 
mkdir -p bin/lazarus
 
mkdir -p bin/lazarus
 
cd bin/lazarus
 
cd bin/lazarus
svn checkout https://svn.freepascal.org/svn/lazarus/trunk laz_trunk
+
</syntaxhighlight>
 +
 
 +
Using git:
 +
git clone https://github.com/User4martin/lazarus.git laz_trunk
 +
 
 +
Using svn:
 +
svn checkout https://svn.freepascal.org/svn/lazarus/trunk laz_trunk
 +
 
 +
<syntaxhighlight lang="sh">
 
//-wait some time...
 
//-wait some time...
 
cd laz_trunk
 
cd laz_trunk
Line 229: Line 264:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
To update your existing trunk source:
+
To update your existing trunk source.
 +
 
 +
Using git:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
cd ~/bin/lazarus/laz_trunk
 
cd ~/bin/lazarus/laz_trunk
svn update .
+
git clean -f -d
 +
git pull
 +
//-wait some time...
 +
make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
 
//-wait some time...
 
//-wait some time...
 +
open startlazarus.app --args "--pcp=~/.laz_trunk"
 +
</syntaxhighlight>
 +
 +
Using svn:
 +
 +
<syntaxhighlight lang="bash">
 +
cd ~/bin/lazarus/laz_trunk
 
svn cleanup --remove-unversioned
 
svn cleanup --remove-unversioned
 +
svn update
 +
//-wait some time...
 
make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
 
make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
 
//-wait some time...
 
//-wait some time...
 
open startlazarus.app --args "--pcp=~/.laz_trunk"
 
open startlazarus.app --args "--pcp=~/.laz_trunk"
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== What does the bigide make argument do? ===
 +
 +
{{BigIDE}}
  
 
== Installing non-release versions of FPC ==
 
== Installing non-release versions of FPC ==
Line 248: Line 301:
 
* [[FPC New Features Trunk|FPC User Changes in Trunk]] - may break existing code.
 
* [[FPC New Features Trunk|FPC User Changes in Trunk]] - may break existing code.
  
Note that since svn trunk is by definition still under development, some of the features may still change before they end up in a release version.
+
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.
  
The source code is kept in a version control system called subversion or '''svn'' for short:
+
The source code is kept in a version control system called subversion or ''svn'' for short, and is mirrored in ''git'':
  
* macOS 10.5 and higher already contain a command line svn client if you have installed the Xcode command line utilities. Users of earlier versions must install an svn client for macOS. 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].
+
* macOS 10.5 and higher already contain a command line svn or git client if you have installed the Xcode command line utilities. You can also use fink, port or brew to get an svn client on newer macOS. 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].
  
 
* You also need the latest released Free Pascal Compiler version (3.2.0 as of July 2020) installed in order to be able to successfully compile the development (trunk) version.
 
* You also need the latest released Free Pascal Compiler version (3.2.0 as of July 2020) installed in order to be able to successfully compile the development (trunk) version.
Line 258: Line 311:
 
Create a directory where you would like to put the source (eg fpc 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:
 
Create a directory where you would like to put the source (eg fpc 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:
  
[]$ cd
+
Using git:
  []$ mkdir fpc
+
  git clone git://github.com/graemeg/freepascal.git fpc
[]$ cd fpc
+
 
  []$ svn checkout https://svn.freepascal.org/svn/fpc/trunk .
+
Using svn:
 +
  svn checkout https://svn.freepascal.org/svn/fpc/trunk fpc
  
 
This will create a directory called 'fpc', which can be later used in the IDE, and download the FPC source to it.
 
This will create a directory called 'fpc', which can be later used in the IDE, and download the FPC source to it.
Line 267: Line 321:
 
To subsequently download/update the latest source changes you can simply do:
 
To subsequently download/update the latest source changes you can simply do:
  
  []$ cd
+
Using git:
 +
<syntaxhighlight lang=sh>
 +
  []$ cd fpc
 +
[]$ git clean -f -d
 +
[]$ git pull
 +
</syntaxhighlight>
 +
 
 +
Using svn:
 +
<syntaxhighlight lang=sh>
 
  []$ cd fpc
 
  []$ cd fpc
 +
[]$ svn cleanup --remove-unversioned
 
  []$ svn update
 
  []$ svn update
 +
</syntaxhighlight>
  
To build and install FPC:
+
To build and install FPC (the highlighted text should be all on one line):
  
 +
<syntaxhighlight lang=sh highlight=4>
 
  []$ cd
 
  []$ cd
 
  []$ cd fpc
 
  []$ cd fpc
[]$ svn cleanup --remove-unversioned
+
  []$ make distclean all FPC=/usr/local/lib/fpc/3.2.0/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
  []$ make clean all FPC=/usr/local/lib/fpc/3.2.0/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64
 
 
  []$ sudo make install OS_TARGET=darwin CPU_TARGET=x86_64
 
  []$ sudo make install OS_TARGET=darwin CPU_TARGET=x86_64
 +
</syntaxhighlight>
 +
 +
You will also need to update the links for the compiler in <tt>/usr/local/bin</tt> which will be pointing to the previous FPC version. For example:
 +
 +
<syntaxhighlight lang=sh>
 +
[]$ cd /usr/local/bin
 +
[]$ sudo rm ppc386
 +
[]$ sudo rm ppcx64
 +
[]$ ln -s /usr/local/lib/fpc/3.3.1/ppc386
 +
[]$ ln -s /usr/local/lib/fpc/3.3.1/ppcx64
 +
</syntaxhighlight>
 +
 +
Note that you will need to build a new <code>ppc386</code> 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):
 +
 +
<syntaxhighlight lang=sh>
 +
[]$ make clean all FPC=/usr/local/lib/fpc/3.2.0/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
 +
</syntaxhighlight>
 +
 +
with these two lines:
 +
 +
<syntaxhighlight lang=sh>
 +
[]$ make clean all FPC=/usr/local/lib/fpc/3.2.0/ppc386 OS_TARGET=darwin CPU_TARGET=i386 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 +
[]$ sudo make install OS_TARGET=darwin CPU_TARGET=i386
 +
</syntaxhighlight>
  
 
== Known issues and solutions ==
 
== Known issues and solutions ==
  
 
=== Installing Lazarus 2.0.8 with FPC 3.2.0 for macOS 10.11+ ===
 
=== Installing Lazarus 2.0.8 with FPC 3.2.0 for macOS 10.11+ ===
 +
 +
<div class="mw-collapsible mw-collapsed">
  
 
* There is a patch needed for Lazarus 2.0.8 so that the Cocoa widgetset can be compiled:  
 
* There is a patch needed for Lazarus 2.0.8 so that the Cocoa widgetset can be compiled:  
 +
 +
<div class="mw-collapsible-content">
  
 
  Index: lcl/interfaces/cocoa/cocoascrollers.pas
 
  Index: lcl/interfaces/cocoa/cocoascrollers.pas
Line 325: Line 418:
 
make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
 
make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
</div></div>
  
 
=== Installing Lazarus 2.0.8, 2.0.10 with FPC 3.2.0 for macOS 10.10 and earlier ===
 
=== Installing Lazarus 2.0.8, 2.0.10 with FPC 3.2.0 for macOS 10.10 and earlier ===
 +
 +
<div class="mw-collapsible mw-collapsed">
  
 
* [Lazarus 2.0.8 only] There is a patch required Lazarus 2.0.8 so that the Cocoa widgetset can be compiled. See [[#Installing Lazarus 2.0.8 with FPC 3.2.0 for macOS 10.11+|above]].
 
* [Lazarus 2.0.8 only] There is a patch required Lazarus 2.0.8 so that the Cocoa widgetset can be compiled. See [[#Installing Lazarus 2.0.8 with FPC 3.2.0 for macOS 10.11+|above]].
 +
 +
<div class="mw-collapsible-content">
 +
 
* [Lazarus 2.0.8 + 2.0.10] There is also a patch needed for FPC 3.2.0. Edit the FPC 3.2.0 source in <tt>../packages/cocoaint/src/CocoaAll.pas</tt> and comment out or remove the CoreImage linking line:
 
* [Lazarus 2.0.8 + 2.0.10] There is also a patch needed for FPC 3.2.0. Edit the FPC 3.2.0 source in <tt>../packages/cocoaint/src/CocoaAll.pas</tt> and comment out or remove the CoreImage linking line:
  
Line 367: Line 466:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==== macOS 10.5 Leopard ====
+
</div></div>
 +
 
 +
==== - macOS 10.5 Leopard ====
 +
 
 +
<div class="mw-collapsible mw-collapsed">
  
 
* After installing Xcode 3.1 (includes the command line tools) for Leopard, the first issue is that Xcode 3.1 does not come with the Clang compiler.
 
* After installing Xcode 3.1 (includes the command line tools) for Leopard, the first issue is that Xcode 3.1 does not come with the Clang compiler.
 +
 +
<div class="mw-collapsible-content">
 +
 
** The solution is to create/add this to the .fpc.cfg file in your home directory:
 
** The solution is to create/add this to the .fpc.cfg file in your home directory:
 
   #include /etc/fpc.cfg ## only add this line if the .fpc.cfg file does not already exist
 
   #include /etc/fpc.cfg ## only add this line if the .fpc.cfg file does not already exist
Line 385: Line 491:
 
     svn co https://svn.freepascal.org/svn/lazarus/tags/lazarus_2_0_10  
 
     svn co https://svn.freepascal.org/svn/lazarus/tags/lazarus_2_0_10  
  
* Compiling FPC 3.2.0 on Leopard is tricky (thanks to Jonas for supplying the solution). Before compiling FPC 3.2.0, make [[#Installing_Lazarus_2.0.8.2C_2.0.10_with_FPC_3.2.0_for_macOS_10.10_and_earlier|this change]] to the source so that it will not attempt to link the missing CoreImage framework. Then compile using the following build320.sh script (enter your password at the prompt for the install to proceed):
+
* Compiling FPC 3.2.0 on Leopard is tricky (thanks to Jonas for supplying the solution). Before compiling FPC 3.2.0, make [[#Installing_Lazarus_2.0.8.2C_2.0.10_with_FPC_3.2.0_for_macOS_10.10_and_earlier|this change]] to the source so that it will not attempt to link the missing CoreImage framework. Then compile using the following <tt>build_320.sh</tt> script (enter your password at the prompt for the install to proceed):
  
 
   <syntaxhighlight lang=sh highlight=4>
 
   <syntaxhighlight lang=sh highlight=4>
Line 397: Line 503:
 
Note: The highlighted line above should all be on one line.
 
Note: The highlighted line above should all be on one line.
  
* Compiling Lazarus 2.0.10 is less tricky. Before compiling Lazarus 2.0.10, make [[#Lazarus_IDE_-_Unable_to_.22run_without_debugging.22| this change]] to the source so that the "run without debugging" option will work. I use the following makelaz.sh script:
+
* Compiling Lazarus 2.0.10 is less tricky. Before compiling Lazarus 2.0.10, make [[#Lazarus_IDE_-_Unable_to_.22run_without_debugging.22| this change]] to the source so that the "run without debugging" option will work. I use the following <tt>build_laz.sh</tt> script:
  
 
   <syntaxhighlight lang=sh highlight=4>
 
   <syntaxhighlight lang=sh highlight=4>
Line 416: Line 522:
  
 
You should now be able to successfully compile and run the Lazarus default blank form project.
 
You should now be able to successfully compile and run the Lazarus default blank form project.
 +
</div></div>
 +
 +
==== - macOS 10.8 Mountain Lion additional steps ====
  
==== macOS 10.8 Mountain Lion additional steps ====
+
<div class="mw-collapsible mw-collapsed">
  
 
* The first issue is that the official Lazarus pkg file downloads will not install on Mountain Lion, giving the error "Lazarus IDE cannot be installed on this disk" being the only disk in the system!
 
* The first issue is that the official Lazarus pkg file downloads will not install on Mountain Lion, giving the error "Lazarus IDE cannot be installed on this disk" being the only disk in the system!
 +
 +
<div class="mw-collapsible-content">
 +
 
** The solution is to download the Lazarus release sources to your home directory. Open an Applications > Utilities > Terminal and:
 
** The solution is to download the Lazarus release sources to your home directory. Open an Applications > Utilities > Terminal and:
 
     svn co https://svn.freepascal.org/svn/lazarus/tags/lazarus_2_0_8
 
     svn co https://svn.freepascal.org/svn/lazarus/tags/lazarus_2_0_8
Line 437: Line 549:
  
 
Now follow the steps [[#Installing Lazarus 2.0.8, 2.0.10 with FPC 3.2.0 for macOS 10.10 and earlier|above]].
 
Now follow the steps [[#Installing Lazarus 2.0.8, 2.0.10 with FPC 3.2.0 for macOS 10.10 and earlier|above]].
 +
</div></div>
  
 
=== Lazarus IDE - Unable to "run without debugging" ===
 
=== 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:
 
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]]
 
[[file:run_dialog_fail.png|350px]]
Line 460: Line 577:
  
 
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.
 
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) ===
 
=== Upgrading from Mojave (10.14) to Catalina (10.15) ===
 +
 +
<div class="mw-collapsible mw-collapsed">
  
 
* Run <code>sudo xcode-select --install</code>
 
* 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
 
* 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...
 
  -Fl/Applications/Xcode.app/Contents/Developer/Toolchain...
 
to
 
to
 
  -Fl/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/
 
  -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 ===
 
=== 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:
+
<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/"
 
   OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
  
 
on the make command line because FPC ignores the <tt>/etc/fpc.cfg</tt> configuration file during builds of itself.
 
on the make command line because FPC ignores the <tt>/etc/fpc.cfg</tt> configuration file during builds of itself.
 +
</div></div>
 +
 +
=== 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 ==
 
== Uninstalling Lazarus and Free Pascal ==
  
 
=== Installed using fink ===
 
=== Installed using fink ===
 +
 +
<div class="mw-collapsible mw-collapsed">
  
 
The complete uninstall of all fpc and lazarus packages is done with:
 
The complete uninstall of all fpc and lazarus packages is done with:
 +
 +
<div class="mw-collapsible-content">
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 493: Line 630:
 
</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]]).
+
For the removal of the Lazarus preferences subdirectory in your home directory, and the files that it contains, see the end of the [[#Installed from packages or source|next section]].
 +
</div></div>
  
 
=== Installed from packages or source ===
 
=== Installed from packages or source ===
 +
 +
<div class="mw-collapsible mw-collapsed">
  
 
Normally you uninstall an application on macOS 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.
 
Normally you uninstall an application on macOS 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.
 +
 +
<div class="mw-collapsible-content">
  
 
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.
 
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.
  
<syntaxhighlight lang="bash">
+
<syntaxhighlight lang="sh">
 +
#!/bin/sh
 +
# Bourne Shell Script
 +
#
 
bin=/usr/local/bin
 
bin=/usr/local/bin
 
share=/usr/local/share
 
share=/usr/local/share
Line 510: Line 655:
 
rm -fv $bin/ppcppc
 
rm -fv $bin/ppcppc
 
rm -fv $bin/ppc386
 
rm -fv $bin/ppc386
 +
rm -fv $bin/ppcx64
 
rm -fv $bin/bin2obj
 
rm -fv $bin/bin2obj
 
rm -fv $bin/data2inc
 
rm -fv $bin/data2inc
Line 534: Line 680:
 
rm -fv $bin/rstconv
 
rm -fv $bin/rstconv
 
rm -fv $bin/unitdiff
 
rm -fv $bin/unitdiff
rm -r $private/lazarus
+
rm -rfv $private/lazarus
rm -r $bin/lazarus
+
rm -rfv $bin/lazarus
rm -r $share/lazarus
+
rm -rfv $share/lazarus
rm -r $share/fpcsrc
+
rm -rfv $share/fpcsrc/fpc-*
rm -r $share/doc/fpc-3.0.3
+
rm -rfv $share/doc/fpc-*
rm -r $share/examples/fpc-3.0.4
 
  
rm -r $lib/fpc
+
rm -rfv $lib/fpc
  
rm -r $receipts/lazarus-*.pkg
+
rm -rfv $receipts/lazarus-*.pkg
rm -r $receipts/fpcsrc-*.pkg
+
rm -rfv $receipts/fpcsrc-*.pkg
rm -r $receipts/fpc-*.pkg
+
rm -rfv $receipts/fpc-*.pkg
  
 
rm -fv /etc/fpc.cfg
 
rm -fv /etc/fpc.cfg
 +
rm -fv ~/.fpc.cfg
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Note that this assumes you have version 3.0.4 of Free Pascal installed. If you have a different version, change the two relevant commands to specify your version.
+
Note that this assumes you have version 3.0.4 of Free Pascal installed. If you have a different version, change the two lines with a version number to specify your version.
  
 
To run this script, change to the directory where it's stored and enter:
 
To run this script, change to the directory where it's stored and enter:
Line 561: Line 707:
 
Then enter your password when prompted.
 
Then enter your password when prompted.
  
=== Lazarus preference folder .lazarus in the home directory ===
+
'''Lazarus preference folder .lazarus in the home directory'''
  
'''''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. macOS normally doesn't show files or folders whose names start with a dot (.). To see this folder and its contents, open an Applications > Utilities > Terminal and enter the following in the terminal window:
+
Lazarus also creates a .lazarus preferences subdirectory 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. macOS normally doesn't show files or folders whose names start with a dot (.). To see this folder and its contents, open an Applications > Utilities > Terminal and enter the following in the Terminal window:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
cd
+
cd .lazarus
 
ls -al
 
ls -al
cd .lazarus
 
ls
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 576: Line 720:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
cd
 
cd
rm -rv .lazarus
+
rm -rfv .lazarus
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
</div></div>
  
 
== See also ==
 
== See also ==

Revision as of 07:00, 26 October 2020

English (en) español (es) 한국어 (ko) русский (ru)

macOSlogo.png

This article applies to macOS only.

See also: Multiplatform Programming Guide


Light bulb  Note: For installation on Apple Silicon/AArch64, please refer to Apple Silicon Support.

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 lead to tears. In brief, here is what you need to do:

  1. Download and install Xcode.
  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 info, either deleting it, or, if it may help someone working with a legacy project, moving it to the bottom of the page.

In general, this is about using both the Carbon and Cocoa Widget Set. 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 (by Apple) limited to 32 bits and you should be aware that it has been removed completely from macOS 10.15 Catalina which only supports 64 bit Cocoa.

Step 1: Download Xcode

You need the Apple Developer tools, which are a part of the Xcode development environment.

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 11.4.x for use on macOS 10.15 Catalina 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 select which version of Xcode to use with the command line utility xcode-select.

Older systems:

The 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 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 (it is quick and easy)-

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

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

Step 3: FPC, FPC Source

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

Download the Free Pascal Compiler (FPC) binaries and FPC source packages 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.

These binary install kits are built by the FPC/Lazarus developers and track formal releases. 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.

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

Other FPC Options

fpcupdeluxe

You could also consider using fpcupdeluxe to install FPC and, perhaps Lazarus.

fink

Alternatively, you can use fink, a package manager for macOS to install FPC. Note at the time of writing (Early 2020) fink offers Lazarus 2.0.6. The extra bonus of fink is easy installation as well as clean removal of a huge number of other open source software packages, including Free Pascal crosscompilers for many processors and systems. The choice for Lazarus is between a Carbon or Cocoa look, a gtk2 look, a Qt4-based and a Qt5-based version:

$ fink install lazarus-aqua
// or
$ fink install lazarus-cocoa
// or
$ fink install lazarus-gtk2
// or
$ fink install lazarus-qt4
// or
$ fink install lazarus-qt5

You will be asked, whether to install a number of dependencies, including the Free Pascal 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.

After installation, Lazarus can be started from the folder /Applications/Fink/. The actual details of FPC and Lazarus are in subdirectories of /sw

With any Lazarus package from fink, these widget sets are supported for your program on macOS:

carbon (Aqua), cocoa, gtk2, qt4 (Aqua), qt5 (Aqua), nogui, win32, win64 and wince.

If you install FPC from fink, you will be fine downloading Lazarus source and compiling as detailed below. However, its possibly not a good idea to mix fink FPC with the Sourceforge binary install of Lazarus.

MacPorts

MacPorts has also a package description of the cocoa-64 bit version of lazarus 2.0.6. Install it with:

$ port install lazarus

Step 4: Install the Lazarus IDE

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!

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.

Compatibility

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.0.8 Lazarus 2.0.10 Lazarus 2.0.12 Lazarus 2.2.y
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**# Compatible**# Compatible# Compatible
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 Compatible Comptaible
macOS 10.12 (Sierra) Compatible^^ Compatible Compatible*** Compatible Compatible Compatible Compatible
macOS 10.13 (High Sierra) Not tested Compatible Compatible*** Compatible Compatible Compatible Comptaible
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 (Big Sur) Not tested Compatible Compatible*** Compatible Compatible Compatible Compatible
macOS 12 (Monterey) Not tested Not tested Not tested Not tested Not tested Not tested Compatible
macOS 13 (Ventura) Not tested Not tested Not tested Not tested Not tested Not tested Compatible
macOS 14 (Sonoma) Not tested Not tested Not tested Not tested Not tested Not tested Compatible
Apple Silicon M series processors
macOS 11 (Big Sur) Not tested Not tested Not tested Compatible†† Compatible†† Compatible††† Compatible*
macOS 12 (Monterey) Not tested Not tested Not tested Compatible†† Compatible†† Compatible††† Compatible*
macOS 13 (Ventura) Not tested Not tested Not tested Compatible†† Compatible†† Compatible††† Compatible*
macOS 14 (Sonoma) Not tested Not tested Not tested Compatible†† Compatible†† Compatible††† Compatible*

x = 0, 2 or 4; y = 0, 2, 4 or 6

^ Carbon interface compiles - Cocoa does not.

^^ Restrictions apply to debugging with gdb.

* Lazarus 2.2.0 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.

** 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 without debugging in the IDE. Can run compiled application outside of the IDE. See Issue #37324. Choose the gdb debugger, change timeout option to false or click through five "timeout" dialogs to run with debugging in the IDE.

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 M series 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 M series processor. Refer to these instructions for compiling the Lazarus IDE.

See the legacy version of this compatibility matrix for recommended installs on very old versions of macOS.

Installing non-release versions of the Lazarus IDE

Lazarus Fixes 2.0

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

  • You almost certainly need to target Cocoa, macOS 10.15 Catalina does 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.
  • Fixes_2_0 is a safer and more stable option than trunk, but still gets the new features much faster than the release version.

Precompiled binaries based on fixes_2_0 are not available from SourceForge but can be obtained from fpcupdeluxe. But here we will discuss downloading source and building. 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.

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_0 https://github.com/User4martin/lazarus.git laz_fixes

Using svn:

svn checkout https://svn.freepascal.org/svn/lazarus/branches/fixes_2_0 laz_fixes

Depending on your internet connection and server congestion this takes a few seconds or a couple of minutes. Then build it:

cd laz_fixes
make 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 supporting 32bit applications, replace above make line with "make LCL_PLATFORM=carbon CPU_TARGET=i386 bigide " and setup 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"

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

Using git:

cd ~/bin/lazarus/laz_fixes
git clean -f -d
git pull
//-wait a little time...
make LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
//-wait some time...
open startlazarus.app --args "--pcp=~/.laz_fixes"

Using svn:

cd ~/bin/lazarus/laz_fixes
svn clean --remove-unversioned
svn update
//-wait a little time...
make LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
//-wait some time...
open startlazarus.app --args "--pcp=~/.laz_fixes"

Lazarus Trunk

Precompiled binaries based on trunk are not available from SourceForge, so here's how to download the trunk source using git and build the Lazarus IDE. 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).

cd ~
mkdir -p bin/lazarus
cd bin/lazarus

Using git:

git clone https://github.com/User4martin/lazarus.git laz_trunk

Using svn:

svn checkout https://svn.freepascal.org/svn/lazarus/trunk laz_trunk
//-wait some time...
cd laz_trunk
make LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
//-wait some time...
open startlazarus.app --args "--pcp=~/.laz_trunk"

To update your existing trunk source.

Using git:

cd ~/bin/lazarus/laz_trunk
git clean -f -d
git pull
//-wait some time...
make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide
//-wait some time...
open startlazarus.app --args "--pcp=~/.laz_trunk"

Using svn:

cd ~/bin/lazarus/laz_trunk
svn cleanup --remove-unversioned
svn update
//-wait some time...
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

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.

The source code is kept in a version control system called subversion or svn for short, and is mirrored in git:

  • macOS 10.5 and higher already contain a command line svn or git client if you have installed the Xcode command line utilities. You can also use fink, port or brew to get an svn client on newer macOS. SVN clients with GUI (graphical user interface) are available from Versiontracker. A quite handy client, which integrates in Finder, is SCPlugin.
  • You also need the latest released Free Pascal Compiler version (3.2.0 as of July 2020) installed in order to be able to successfully compile the development (trunk) version.

Create a directory where you would like to put the source (eg fpc 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:

Using git:

git clone git://github.com/graemeg/freepascal.git fpc

Using svn:

svn checkout https://svn.freepascal.org/svn/fpc/trunk fpc

This will create a directory called 'fpc', which can be later used in the IDE, and download the FPC source to it.

To subsequently download/update the latest source changes you can simply do:

Using git:

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

Using svn:

 []$ cd fpc
 []$ svn cleanup --remove-unversioned
 []$ svn update

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.0/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
 []$ ln -s /usr/local/lib/fpc/3.3.1/ppc386
 []$ 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.0/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.0/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

Installing Lazarus 2.0.8 with FPC 3.2.0 for macOS 10.11+

  • There is a patch needed for Lazarus 2.0.8 so that the Cocoa widgetset can be compiled:
Index: lcl/interfaces/cocoa/cocoascrollers.pas
===================================================================
--- lcl/interfaces/cocoa/cocoascrollers.pas     (revision 63408)
+++ lcl/interfaces/cocoa/cocoascrollers.pas     (revision 63409)
@@ -31,8 +31,6 @@
   cocoa_extra, CocoaPrivate;

 type
-  TSetDocumentViewType = {$if FPC_FULLVERSION = 30200}id{$else}NSView{$endif};
-
   { TCocoaScrollView }

   TCocoaScrollView = objcclass(NSScrollView)
@@ -51,7 +49,7 @@
     procedure resetCursorRects; override;
     function lclClientFrame: TRect; override;
     function lclContentView: NSView; override;
-    procedure setDocumentView(aView:  TSetDocumentViewType); override;
+    procedure setDocumentView(aView: NSView); override;
     procedure scrollContentViewBoundsChanged(notify: NSNotification); message 'scrollContentViewBoundsChanged:';
     procedure resetScrollRect; message 'resetScrollRect';

@@ -647,7 +645,7 @@
   Result:=documentView;
 end;

-procedure TCocoaScrollView.setDocumentView(aView: TSetDocumentViewType);
+procedure TCocoaScrollView.setDocumentView(aView: NSView);
 begin
   inherited setDocumentView(aView);
   resetScrollRect;
  • After making this patch, recompile Lazarus 2.0.8 from within itself or with this build_laz.sh shell script (adjust path for Lazarus source as required):
#!/bin/sh
cd ~/Documents/Lazarus/
svn cleanup --remove-unversioned
make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide

Installing Lazarus 2.0.8, 2.0.10 with FPC 3.2.0 for macOS 10.10 and earlier

  • [Lazarus 2.0.8 only] There is a patch required Lazarus 2.0.8 so that the Cocoa widgetset can be compiled. See above.
  • [Lazarus 2.0.8 + 2.0.10] There is also a patch needed for FPC 3.2.0. Edit the FPC 3.2.0 source in ../packages/cocoaint/src/CocoaAll.pas and comment out or remove the CoreImage linking line:
 unit CocoaAll;
 interface
 
 {$linkframework Cocoa}
 {$linkframework Foundation}
 //{$linkframework CoreImage} **Comment out this line**
 {$linkframework QuartzCore}
 {$linkframework CoreData}
 {$linkframework AppKit}
  • To rebuild FPC 3.2.0 with the patch, you need an FPC 3.0.4 binary installation. My build_320.sh shell script to rebuild and reinstall FPC 3.2.0 (adjust path for FPC source as required):
#!/bin/sh
cd /usr/local/share/src/fpc-3.2.0/
svn cleanup --remove-unversioned
make clean all FPC=/usr/local/lib/fpc/3.0.4/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
make install FPC=/usr/local/lib/fpc/3.0.4/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64

Note that:

  • if more than one line above is highlighted, all the highlighted content should be on one line;
  • you may need to change the second line depending on where your FPC Source code is installed;
  • you will almost certainly need to run the script by using sudo.

Now rebuild Lazarus with this build_laz.sh shell script (adjust path for Lazarus source as required):

#!/bin/sh
cd ~/Documents/Lazarus/
svn cleanup --remove-unversioned
make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide

- macOS 10.5 Leopard

  • After installing Xcode 3.1 (includes the command line tools) for Leopard, the first issue is that Xcode 3.1 does not come with the Clang compiler.
    • The solution is to create/add this to the .fpc.cfg file in your home directory:
 #include /etc/fpc.cfg ## only add this line if the .fpc.cfg file does not already exist
 -WM10.5
 -Aas-darwin
  • The second issue is that the official Lazarus Mac OS X i386 download of FPC is FPC 3.0.4 and not 3.2.0.
    • The solution is to download the source for FPC 3.2.0 to your home directory. Open an Applications > Utilities > Terminal and:
   svn co https://svn.freepascal.org/svn/fpc/tags/release_3_2_0 
  • 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. Open an Applications > Utilities > Terminal and:
   svn co https://svn.freepascal.org/svn/lazarus/tags/lazarus_2_0_10 
  • Compiling FPC 3.2.0 on Leopard is tricky (thanks to Jonas for supplying the solution). Before compiling FPC 3.2.0, make this change to the source so that it will not attempt to link the missing CoreImage framework. Then compile using the following build_320.sh script (enter your password at the prompt for the install to proceed):
   #!/bin/sh
   cd /Users/$USER/release_3_2_0/
   svn cleanup
   make clean all FPC="/usr/local/lib/fpc/3.0.4/ppc386" OS_TARGET=darwin CPU_TARGET=i386 CPU_SOURCE=i386 OPT="-WM10.5 -Aas-darwin -Xs-" 
   sudo make install OS_TARGET=darwin CPU_TARGET=i386 CPU_SOURCE=i386

Note: The highlighted line above should all be on one line.

  • Compiling Lazarus 2.0.10 is less tricky. Before compiling Lazarus 2.0.10, make this change to the source so that the "run without debugging" option will work. I use the following build_laz.sh script:
  #!/bin/sh
  cd /Users/$USER/lazarus_2_0_10
  svn cleanup
  make distclean all LCL_PLATFORM=carbon CPU_SOURCE=i386 CPU_TARGET=i386 bigide OPT="-WM10.5 -Aas-darwin -Xs- -dCarbonDontUseCocoa"

Note: The highlighted line above should all be on one line.

  • Finally, launch the newly compiled lazarus.app and adjust these Lazarus settings:
    • Tools > Options > Environment > Files > Compiler executable: this should be set to /usr/local/bin/ppc386.
    • Project > Project Options > Custom Options: add -WM10.5 to the Custom options.
    • Project > Project Options > Config and Target > Target CPU family: set to i386.
    • Project > Project Options > Config and Target > Current LCL widgetset: set to Carbon.
    • Project > Project Options: in the left pane, at the bottom, check "Set compiler options as default".

You should now be able to successfully compile and run the Lazarus default blank form project.

- macOS 10.8 Mountain Lion additional steps

  • The first issue is that the official Lazarus pkg file downloads will not install on Mountain Lion, giving the error "Lazarus IDE cannot be installed on this disk" being the only disk in the system!
    • The solution is to download the Lazarus release sources to your home directory. Open an Applications > Utilities > Terminal and:
   svn co https://svn.freepascal.org/svn/lazarus/tags/lazarus_2_0_8
   =or=
   svn co https://svn.freepascal.org/svn/lazarus/tags/lazarus_2_0_10
  • Unfortunately the compiler and assembler in the last version of Xcode and its command line tools available for Mountain Lion is too old to compile Lazarus.
   cd /usr/bin
   sudo mv clang clang.OLD
   sudo ln -s /Users/$USER/clang/bin/clang clang
   sudo mv as as.OLD
   sudo ln -s /Users/$USER/clang/bin/as as

Now follow the steps above.

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

Installed using fink

The complete uninstall of all fpc and lazarus packages is done with:

fink purge --recursive fpc-config

If you want to preserve changes to the preference file /sw/etc/fpc.cfg, do:

fink remove --recursive fpc-config

For the removal of the Lazarus preferences subdirectory in your home directory, and the files that it contains, see the end of the next section.

Installed from packages or source

Normally you uninstall an application on macOS 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.

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.

#!/bin/sh
# Bourne Shell Script
#
bin=/usr/local/bin
share=/usr/local/share
lib=/usr/local/lib
receipts=/Library/Receipts
private=/private/etc

rm -fv $bin/ppcppc
rm -fv $bin/ppc386
rm -fv $bin/ppcx64
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 -rfv $private/lazarus
rm -rfv $bin/lazarus
rm -rfv $share/lazarus
rm -rfv $share/fpcsrc/fpc-*
rm -rfv $share/doc/fpc-*

rm -rfv $lib/fpc

rm -rfv $receipts/lazarus-*.pkg
rm -rfv $receipts/fpcsrc-*.pkg
rm -rfv $receipts/fpc-*.pkg

rm -fv /etc/fpc.cfg
rm -fv ~/.fpc.cfg

Note that this assumes you have version 3.0.4 of Free Pascal installed. If you have a different version, change the two lines with a version number to specify your version.

To run this script, change to the directory where it's stored and enter:

chmod +x uninstallLaz.sh
sudo ./uninstallLaz.sh

Then enter your password when prompted.

Lazarus preference folder .lazarus in the home directory

Lazarus also creates a .lazarus preferences subdirectory 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. macOS normally doesn't show files or folders whose names start with a dot (.). To see this folder and its contents, open an Applications > Utilities > Terminal and enter the following in the Terminal window:

cd .lazarus
ls -al

To remove it, execute the following commands:

cd
rm -rfv .lazarus

See also

  • 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.
  • Legacy Information for details of installing Lazarus on PowerPC-based Macs, old Xcode versions, the gdb debugger, etc.