Talk:Installing Lazarus on macOS
This is a draft of a new "top half" for the main page. Its about getting a recent version of lazarus going on a recent version of OSX. I need to get a lot of formatting done and a polite way to tuck the historical data down the bottom. Note there is absolutely nothing new from me here, its all stuff scattered across the forum and wiki. I'll be back ....
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 -
- Download and install Xcode.
- Install the global command line tools for Xcode.
- Install gdb - sort of but not really optional.
- Install Free Pascal Compiler, FPC Source and Lazarus
- Speak to Lazarus about gdb.
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.
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.
Step 1. Download Xcode.
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) -
mv Downloads/Xcode-beta.app /Developer/. sudo xcode-select -s /Developer/Xcode-beta.app/Contents/Developer
Step 2. Xcode Command Line Tools
This is shown here as a separate step because it 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)-
Step 3 install gdb
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
- Install brew and use brew to install gdb- http://wiki.freepascal.org/GDB_on_OS_X_Mavericks_and_Xcode_5
- 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.
Step 4 FPC, FPC Source and Lazarus
Get and install, in this order, the FPC, FPC Source, Lazarus. I used Lazarus 1.8rc4, its very mature and probably about to become 1.8 pretty soon. Get 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).
Step 5 Tell Lazarus about starting gdb
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.
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.