Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Share:
Notifications
Clear all

[Solved] Lazarus Pascal - macOS - How to make a universal binary for Apple Silicon (M1) and Intel CPU's

2 Posts
1 Users
0 Reactions
4,800 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2805
Topic starter  

Assuming you're using FPCUpDeluxe (free), and you have FPC and Lazarus installed through FPCUpDeluxe;

1) In FPCUpDeluxe, install the ARM compiler:

Click the tab "cross", check "aarch64" and "darwin" and click the "Install Compiler" button.
The FPC ARM compiler will now be installed next to your Intel compiler.

2) In Lazarus, you will need to compile the Intel and M1 binary independently.

In Lazarus got to the menu "Project" - "Project Options". Under "Compiler options" go to "Config and Target".
So far I found that, per platform, you only need to set the "CPU Family" to either "aarch64" (M1) or "x86_64" (Intel).
Select one and build the binary file. In the project directory now rename the file by adding the CPU family.
Do the same for the other CPU family.

Example: project1

Set target CPU to Intel and Build the Intel binary, and rename it to "project1_x86".
Next set the target CPU to aarch64 and build the M1 binary, and rename it to "project1_M1".

3) In Terminal merge both files to the Universal binary by using the "lipo" tool.

In Terminal:

lipo -create -output project1 project1_M1 project1_x86
strip project1

 

You now have a universal binary which needs to be used to replace the symbolic link in your final app bundle's MacOS directory.
 
You can check that you have created a universal binary with this command:
 
file project1
 
Output similar to this:
 
project1: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64]
project1 (for architecture x86_64): Mach-O 64-bit executable x86_64
project1 (for architecture arm64): Mach-O 64-bit executable arm64

 

Note that binaries for M1 must be signed, as it seems that they will not run on any M1 Mac if not signed.
Since I do not have M1 hardware, I'm unable to test the signing process (my usual signing process of the universal binary seems to work OK for Intel Mac's).


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2805
Topic starter  

Note:

Do not forget that additional tools and/or libraries need to be compiled for the same CPU platform as well!


   
ReplyQuote
Share: