tldr: Option 3 below will convert all of the example projects to run on Mac Mseries
For M-series Macs (M1, M2, etc. aka Apple Silicon or arm64 or aarch64) the included examples won't work without doing a few small things.
These one-time changes will probably also need to be done to any other example projects you get off the internet or any projects you created in the past.
In the project file (<
Project Name>
.lpi) there are two options that need to be set:
-framework IOKit
and
-WM11.0
In the main .lpr or .pas file in the project folder add this to the uses list:
CocoaAll,
There are three options:
- Manually change one project/example at a time (most informative)
- Commands to change one project/example at a time
- Commands to change all of the examples at once (easiest)
Edit the <
Project Name>
.lpi file of a project with a text editor
- Find this near the bottom of the file
</Linking>
</CompilerOptions>
and replace it with
<Options>
<PassLinkerOptions Value="True"/>
<LinkerOptions Value="'-framework IOKit'"/>
</Options>
</Linking>
<Other>
<CustomOptions Value="'-WM11.0'"/>
</Other>
</CompilerOptions>
- Edit the main
.lpr
or.pas
file of the project with a text editor find the uses section and addCocoaAll
to that section. OR you can load the project in Lazarus and change it in the.lpr
or.pas
file from there. hint: you will probably only need to change the.pas
file if there is no.lpr
file.
Run these commands in the folder of the project you wish to change:
sed -i '' '/<\/Linking>/,/<\/CompilerOptions>/c\
<Options>\
<PassLinkerOptions Value="True"/>\
<LinkerOptions Value="'-framework IOKit'"/>\
</Options>\
</Linking>\
<Other>\
<CustomOptions Value="'-WM11.0'"/>\
</Other>\
</CompilerOptions>' *.lpi
sed -i '' '/^uses/ s/^uses/& CocoaAll,/' *.lpr
sed -i '' '/^uses/ s/^uses/& CocoaAll,/' *.pas
Run these commands from the root folder of the repo to make these changes to every project in the examples folder.
find examples -type f -name "*.lpi" -print0 | xargs -0 sed -i '' '/<\/Linking>/,/<\/CompilerOptions>/c\
<Options>\
<PassLinkerOptions Value="True"/>\
<LinkerOptions Value="'-framework IOKit'"/>\
</Options>\
</Linking>\
<Other>\
<CustomOptions Value="'-WM11.0'"/>\
</Other>\
</CompilerOptions>'
find examples -type f -name "*.lpr" -print0 | xargs -0 sed -i '' '/^uses/ s/^\(uses\)/\1 CocoaAll,/'
find examples -type f -name "*.pas" -print0 | xargs -0 sed -i '' '/^uses/ s/^\(uses\)/\1 CocoaAll,/'
If you run this twice then you will probably have to edit the .lpr files manually to remove the extra CocoAll,
which is easy and not a big deal. The compiler will tell you about it if you run it twice and don't notice.
After doing one of the options above you should be able to run the examples by choosing one and loading that projects .lpi
file into Lazarus. At that point select the menu option: Run->Run Without Debugging
and the example should fire right up. You should be able to tweak the examples to your hearts content and it should all work.
This should work for all of the included example projects but if a few of them don't work then a little manual investigation into that project should solve it.
- The main pascal file should have
CocoaAll
in its uses section. Usually its a.lpr
file but sometimes it might be.pas
file. - The .lpi file should have the
-WM11
and the-framework IOKit
options added near the end - I made a video about this process since it could help to see me do it.
- If you need to redownload the examples from the github I don't blame you, I had to do that several times to make this :)
- You can use Option 2 above to try again on just one project.
This is not a problem wth Ray4Laz. This is a small problem with the build of the Free Pascal Compiler on Mac Mseries and can safely be ignored. It shows up as an error but I have seen no ill effects and everything I have done has worked in spite of this error showing up in every build.
This is a small problem related to the fpc compiler that you can either safely ignore or you can fix it in your own local build by changing just one character in a file if you want to. I made a video about fixing this which in a nutshell involves editing lazarus/fpcsrc/compiler/systems/t_darwin.pas
and in that file changing macosx_version_min
to macos_version_min
and recompiling fpc. Yes It is literally just a one character change. That should fix it until you update fpc from source in which case you will have to do this small fix again.
examples/shaders/shaders_custom_uniform
compiles fine but doesn't seem to run. Can you figure out why? Clues: Once you have compiled it if you go into the ray4laz/binary folder you can run the compiled version and see what error you get. I gotERROR: 0:46: Use of undeclared identifier 'color'
among others.