Raylib Simple Project doesn't build on Mac M1
Summary
I'm on an M1 Macbook Air with OS Sonoma 14.5 and I get the attached error log when I open a new raylib simple project and hit build. I didn't change the code at all.
Build Logs
I tried installing ray4laz twice in two different ways and got the same basic log both times.
Installed using fpcupdeluxe installer
Here is the build log with errors from the new raylib simple project when I installed ray4laz using the fpcupdeluxe installer:: raylib simple project errors from fpcupdeluxe install.txt
Installed manually using .lpk files
Here is the build log with errors from the new raylib simple project when I installed ray4laz manually using the .lpk files raylib simple project errors from manual install.txt
Summary of the error
Undefined symbols for architecture arm64:
"_BeginDrawing", referenced from:
_PASCALMAIN in game.o
"_ClearBackground", referenced from:
_PASCALMAIN in game.o
"_CloseWindow", referenced from:
_PASCALMAIN in game.o
"_DrawText", referenced from:
_PASCALMAIN in game.o
"_EndDrawing", referenced from:
_PASCALMAIN in game.o
"_GetScreenToWorldRay", referenced from:
_RAYLIB_$$_GETMOUSERAY$TVECTOR2$TCAMERA3D$$TRAY in raylib.o
"_InitWindow", referenced from:
_PASCALMAIN in game.o
"_SetTargetFPS", referenced from:
_PASCALMAIN in game.o
"_WindowShouldClose", referenced from:
_PASCALMAIN in game.o
ld: symbol(s) not found for architecture arm64
Installation Output with ld warnings:
Here is the installation output from fpcupdeluxe: Ray4LazInstallLogFromFPCUpDeluxe.txt
Why didn't I use the Online Package Manger?
Short answer: I tried but couldn't.
For background I initially tried using the "online package manager" as mentioned in the screenshots however there were enormous lazarus based build problems on M1 mac and after hours of attempts I got it all compiled using this build tool called fpcupdeluxe. However that build tool builds it without the online package manager unfortunately.
Finally
I wish I could figure this out on my own but I couldn't do it. But hmu if I can help test things or if you have anything I should try to get it working. I would like to help figure it out. :)
Good. I understand your problem. There are no compiled libraries for the arm architecture. I'll try to add support tomorrow. Your help will be needed for testing
Unfortunately, the task of cross-compilation turned out to be very difficult for me.
But you can try to compile the library yourself.
Here's the quick instructions:
- From the command line
export MACOSX_DEPLOYMENT_TARGET=10.9
- Install XCode tools (don't forget to then update the tools in the Mac App Store after!)
xcode-select --install
- Build raylib (Again, this is so the export line takes effect)
git clone https://github.com/raysan5/raylib.git
cd raylib/src
make
You may do the otool check with the file in raylib/src/libraylib.a here if you like. (LC_VERSION_MIN_MACOSX should be version 10.4), and we're good!
copy file libraylib.a to Ray4Laz/libs/aarch64-macosx <--- I'm not sure if the folder should be named that way for the mac m1 architecture. you can see this by creating any empty project and compiling it. in the project's lib folder.
yes and you should use ray4laz from the master branch
open ray4laz.lpk and compile open ray4laz_designtime.lpk compile and install
Ok I'm on it!
Here is the new Libs and Packages folders along with a similar error log to before.
To be sure: I am just starting a new simple project and hitting compile. Is that correct? That should work right?
Hint: (11030) Start of reading config file /etc/fpc.cfg
Hint: (11031) End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 3.2.2 [2021/05/16] for aarch64
Copyright (c) 1993-2021 by Florian Klaempfl and others
(1002) Target OS: Darwin for AArch64
(3104) Compiling /Users/johnmcgarey/tmp/game.lpr
(9009) Assembling game
(9015) Linking /Users/johnmcgarey/tmp/game
ld: warning: -multiply_defined is obsolete
-macosx_version_min has been renamed to -macos_version_min
Undefined symbols for architecture arm64:
"_BeginDrawing", referenced from:
_PASCALMAIN in game.o
"_ClearBackground", referenced from:
_PASCALMAIN in game.o
"_CloseWindow", referenced from:
_PASCALMAIN in game.o
"_DrawText", referenced from:
_PASCALMAIN in game.o
"_EndDrawing", referenced from:
_PASCALMAIN in game.o
"_GetScreenToWorldRay", referenced from:
_RAYLIB_$$_GETMOUSERAY$TVECTOR2$TCAMERA3D$$TRAY in raylib.o
"_InitWindow", referenced from:
_PASCALMAIN in game.o
"_SetTargetFPS", referenced from:
_PASCALMAIN in game.o
"_WindowShouldClose", referenced from:
_PASCALMAIN in game.o
ld: symbol(s) not found for architecture arm64
An error occurred while linking
Error: (9013) Error while linking
Fatal: (10026) There were 1 errors compiling module, stopping
Fatal: (1018) Compilation aborted
Error: /usr/local/bin/ppca64 returned an error exitcode
Are you uploading as a static library?
Add to raylib.inc
{$IFDEF DARWIN} {$DEFINE RAY_STATIC} {$IFEND}
Although it may be a matter of static linking. It was not possible to do it under Windows.
Try to create a dynamic library
make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED # To make the dynamic shared version.
libraylib.dylib copy to project folder
{$IFDEF DARWIN} {.$DEFINE RAY_STATIC} {$IFEND}
there may not be enough libraries for static linking
you can try to rewrite this one for mac os
implementation uses Math;
{$IFDEF linux} {$IFDEF RAY_STATIC} {$linklib c} {$linklib m} {$linklib dl} {$linklib pthread} {$linklib libraylib.a} {$endif} {$endif}
Thanks for the ideas! I made a .a file before. Ill try to make a dynamic library just like you described. I have to admit to being just barely above water in terms of my abilities but I am learning a lot :)
Update: I built a dylib like you suggested and copied it into the ray4laz folder and then edited the raylib.inc as suggested and compiled ray4laz and then compiled and installed ray4lazdesigntime and got the same errors. Here are the Libs and Package folders Ray4Laz Libs and Package folders with error logs.zip
I'm starting to wonder if my process is correct. I've been compiling and installing the packages from Package->Open Package File (.lpk) it then says
The package "ray4laz_designtime 5.5" was marked for installation.
Currently Lazarus only supports static linked packages. The real installation needs rebuilding and restarting of Lazarus.
Do you want to rebuild Lazarus now?
``` and I click yes.
What is your process for compiling and installing the packages?
there may not be enough libraries for static linking
you can try to rewrite this one for mac os
implementation uses Math;
{$IFDEF linux} {$IFDEF RAY_STATIC} {$linklib c} {$linklib m} {$linklib dl} {$linklib pthread} {$linklib libraylib.a} {$endif} {$endif}
For this I'm kind of lost, does this mean putting this code in a new file and putting it in the build path somewhere?
No need if you use a dynamic library. And os x will most likely need other libraries for the static version. This is just an example
I still get these errors but I got these clues:
- I get the same errors if I go into the examples and try building the basic_window from the command line with fpc.
- I used nm to verify that those symbols were in the .a and the .dylib
- I used
lipo -infoto verify that the architecture of both was 'arm64' - I even got the same errors in a totally different project Raylib4.0Pascal when I tried compiling with fpc from the command line.
Here are the errors:
"_BeginDrawing", referenced from:
_PASCALMAIN in game.o
"_ClearBackground", referenced from:
_PASCALMAIN in game.o
"_CloseWindow", referenced from:
_PASCALMAIN in game.o
"_DrawText", referenced from:
_PASCALMAIN in game.o
"_EndDrawing", referenced from:
_PASCALMAIN in game.o
"_GetScreenToWorldRay", referenced from:
_RAYLIB_$$_GETMOUSERAY$TVECTOR2$TCAMERA3D$$TRAY in raylib.o
"_InitWindow", referenced from:
_PASCALMAIN in game.o
"_SetTargetFPS", referenced from:
_PASCALMAIN in game.o
"_WindowShouldClose", referenced from:
_PASCALMAIN in game.o
What should I try next?
I have the same problem on my MacOS Mojave (x86_64-darwin) and I think I've managed to solve it. I'm using latest (with fixes) Lazarus FPCUPdeluxe build.
These are the steps for a static build:
- Clone Ray4Laz and RayLib repositories
- Compile RayLib with:
make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHAREDmake PLATFORM=PLATFORM_DESKTOP - Copy: libraylib.5.5.0.dylib, libraylib.550.dylib, libraylib.a, libraylib.dylib –> path_to/ray4laz/libs/x86_64-darwin
- Compile
ray4laz.lpk - Compile and install
ray4laz_designtime.lpk - Add
{$LINKLIB raylib.a}into your_project.lpr file (right after{$mode objfpc}{$H+}) - Add
CocoaAllunit into your_project.lpruses - Project–>Project Options–>Compiler Options–>Compilation and Linking–>Linking–>Pass options to linker... :
add
'-framework IOKit'– with quotes! - Build your project...
If on step 6 you specify {$LINKLIB raylib} (without .a), then it will use dynamic library. But in this case you have to tell your app where are RayLib compiled library files located. Otherwise you'll not be able to run your app. I've simply added: Run–>Run Parameters...–>Environment–>User overrides, variable LD_LIBRARY_PATH where value is the path to the directory with RayLib *.dylib files.
I hope I didn't forget anything.
PS. You have to replace x86_64-darwin with aarch64-darwin.
PPS. I didn't test raygui, raymath... Also, one of the remaining tasks is to create the
I have the same problem on my MacOS Mojave (x86_64-darwin) and I think I've managed to solve it. I'm using latest (with fixes) Lazarus FPCUPdeluxe build.
These are the steps for a static build:
1. Clone Ray4Laz and RayLib repositories 2. Compile RayLib with: `make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED` `make PLATFORM=PLATFORM_DESKTOP` 3. Copy: libraylib.5.5.0.dylib, libraylib.550.dylib, libraylib.a, libraylib.dylib –> path_to/ray4laz/libs/x86_64-darwin 4. Compile `ray4laz.lpk` 5. Compile and install `ray4laz_designtime.lpk` 6. Add `{$LINKLIB raylib.a}` into your_project.lpr file (right after `{$mode objfpc}{$H+}`) 7. Add `CocoaAll` unit into your_project.lpr `uses` 8. Project–>Project Options–>Compiler Options–>Compilation and Linking–>Linking–>Pass options to linker... : add `'-framework IOKit'` – with quotes! 9. Build your project...If on step 6 you specify
{$LINKLIB raylib}(without.a), then it will use dynamic library. But in this case you have to tell your app where are RayLib compiled library files located. Otherwise you'll not be able to run your app. I've simply added: Run–>Run Parameters...–>Environment–>User overrides, variableLD_LIBRARY_PATHwhere value is the path to the directory with RayLib *.dylib files.I hope I didn't forget anything.
PS. You have to replace
x86_64-darwinwithaarch64-darwin. PPS. I didn't test raygui, raymath... Also, one of the remaining tasks is to create the .app bundle in case of dynamic linking, or if the project has any assets.
Vlad, thank you very much for the work you have done. Following your instructions, I changed the package. Could you test the latest changes.
You only need to use step 3.
I've tested last commit, but there is 2 problems.
- In step 8 there is a check box, that needs to be checked for
'-framework IOKit'to workPass options to linker with "-k", delimiter is space - In
raylib.incfile you have to remove dot in{.$DEFINE RAY_STATIC}directive (raylib.inc.patch)
After that, build and run will be succeed.
I've tested last commit, but there is 2 problems.
1. In step 8 there is a check box, that needs to be checked for `'-framework IOKit'` to work `Pass options to linker with "-k", delimiter is space` 2. In `raylib.inc` file you have to remove dot in `{.$DEFINE RAY_STATIC}` directive ([raylib.inc.patch](https://github.com/user-attachments/files/17560400/raylib.inc.patch))After that, build and run will be succeed.
Fixed
- Compile RayLib with:
make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHAREDmake PLATFORM=PLATFORM_DESKTOP
@GuvaCode here are the arm64 .a and .dylib files that I just built from Raylib master (I confirmed with lipo -info they are arm64) aarch64-darwin.zip
- Compile RayLib with:
make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHAREDmake PLATFORM=PLATFORM_DESKTOP@GuvaCode here are the arm64 .a and .dylib files that I just built from Raylib master (I confirmed with lipo -info they are arm64) aarch64-darwin.zip
Did you manage to launch it? Is everything working?
I can confirm that after reinstalling Ray4Laz from the last commit, new raylib simple project builds and runs perfectly.
Thank you!
95% there! Thanks to both of you @vvladonline and @GuvaCode for helping me make so much progress.
The only one remaining is:
Error: linker: Undefined symbols for architecture arm64:
Error: linker: "___chkstk_darwin", referenced from:
Debug: "___chkstk_darwin", referenced from:
Debug: _msf_gif_frame in libraylib.a[2](rcore.o)
Debug: _sinfl_decompress in libraylib.a[2](rcore.o)
Debug: _ScanDirectoryFilesRecursively in libraylib.a[2](rcore.o)
Debug: _stbi_load_gif_from_memory in libraylib.a[4](rtextures.o)
Debug: _stbi_zlib_decode_malloc_guesssize in libraylib.a[4](rtextures.o)
Debug: _stbi_zlib_decode_malloc in libraylib.a[4](rtextures.o)
Debug: _stbi_zlib_decode_malloc_guesssize_headerflag in libraylib.a[4](rtextures.o)
Debug: ...
Error: ld: symbol(s) not found for architecture arm64
Here is the full log in case that helps anyone Just one linker error now.txt
95% there! Thanks to both of you @vvladonline and @GuvaCode for helping me make so much progress.
The only one remaining is:
Error: linker: Undefined symbols for architecture arm64: Error: linker: "___chkstk_darwin", referenced from: Debug: "___chkstk_darwin", referenced from: Debug: _msf_gif_frame in libraylib.a[2](rcore.o) Debug: _sinfl_decompress in libraylib.a[2](rcore.o) Debug: _ScanDirectoryFilesRecursively in libraylib.a[2](rcore.o) Debug: _stbi_load_gif_from_memory in libraylib.a[4](rtextures.o) Debug: _stbi_zlib_decode_malloc_guesssize in libraylib.a[4](rtextures.o) Debug: _stbi_zlib_decode_malloc in libraylib.a[4](rtextures.o) Debug: _stbi_zlib_decode_malloc_guesssize_headerflag in libraylib.a[4](rtextures.o) Debug: ... Error: ld: symbol(s) not found for architecture arm64Here is the full log in case that helps anyone Just one linker error now.txt
Error: -macosx_version_min has been renamed to -macos_version_min export MACOSX_DEPLOYMENT_TARGET=11.0 but most likely you need 14.5
in folder raylib/src --> make clean rebuild raylib
I can confirm that after reinstalling Ray4Laz from the last commit, new
raylib simple projectbuilds and runs perfectly. Thank you!
I deployed the VM and compiled with raygui nested Could you check it out? I'm not sure it's going to work at all.
I deployed the VM and compiled with raygui nested Could you check it out? I'm not sure it's going to work at all.
Yes, it's works. I've reinstalled Ray4Laz and build&run simple project.
But i'm not sure if all these files are needed. I removed libraylib.550.dylib and libraylib.dylib symlinks, renamed libraylib.5.5.0.dylib to libraylib.dylib and the project still builds and runs fine. I left libraylib.a as is.
I deployed the VM and compiled with raygui nested Could you check it out? I'm not sure it's going to work at all.
Yes, it's works. I've reinstalled Ray4Laz and build&run simple project. But i'm not sure if all these files are needed. I removed
libraylib.550.dylibandlibraylib.dylibsymlinks, renamedlibraylib.5.5.0.dylibtolibraylib.dyliband the project still builds and runs fine. I leftlibraylib.aas is.
Thank you. Yes, symbolic links are not needed.
export MACOSX_DEPLOYMENT_TARGET=11.0 but most likely you need 14.5
in folder raylib/src --> make clean rebuild raylib
I did make clean and then rebuilt raylib then copied the files over and rebuilt my project in lazarus. I tried it with several deployment targets and got almost the same errors as the errors above each time.
MACOSX_DEPLOYMENT_TARGET10.9.txt MACOSX_DEPLOYMENT_TARGET11.0.txt MACOSX_DEPLOYMENT_TARGET14.5.txt
Now I'm looking into what to do about
Error: -macosx_version_min has been renamed to -macos_version_min
Big Progress via manual edits
Error: -macosx_version_min has been renamed to -macos_version_min
I went into the project folder and manually changed the latest link35561.res from macosx_version_min to macos_version_min and then changed the version to 11.0 and manually ran ./ppaslink.sh and it built and I could run it! Thats the first time it has worked for me!
I'm going to try to reproduce that and see if it works again. Update: yeah this process worked:
- Lazarus: New -> Raylib Simple Project
- Save it somewhere
- Build it (it will fail)
- Leave Lazarus: Go to that folder in terminal
- edit the link12345.res file (some other number ofc - pick the latest)
- change
macosx_version_mintomacos_version_min - change the number below that from 10.9 to 11
- ./ppaslink.sh
- like 4 lines of output and the game will be sitting right there!
@JudgeGroovyman I have changed the project options for arm https://forum.lazarus.freepascal.org/index.php?topic=43188.0
please test it simple project
Can I watch this https://gitlab.kitware.com/cmake/cmake/-/issues/25530
Please describe the solution as you compiled it. I didn't really understand. from where link 12345.res and ./ppaslink.sh .
please attach the files libraylib on which you are running
@JudgeGroovyman You also can search in your fpc.cfg (local or global) file for -WM option. In my fpc.cfg I have -WM10.9
@GuvaCode those files (*.res) is left by linker after build failure.
So, using them is wrong solution.
please attach the files libraylib on which you are running
First of all here are the libraries i'm running that worked LibsforMacM1Works.zip
@JudgeGroovyman I have changed the project options for arm
please test it simple project
Sure I will go test
Success!
Change -WM11 to -WM11.0 in ray4laz/package/ray4laz_simpleprj.pas and it works!
Details of what I did
Before I figured out the problem
I changed my fpc.cfg from -WM10.9 to -WM11 and Lazarus wouldn't even start. I changed it to -WM11.0 and Lazarus started. I copying my arm64 libs over to the ray4laz/libs/aarch64-darwin folder. Then I compiled and imported the ray4laz packages into lazarus, then opened a new->raylib-simple-project and saved and compiled it. It didn't build and said Error: Illegal parameter: -WM11 so I went and double checked my fpc.config and tried various things and (because I didn't know better) even rebuilt fpc and lazarus and it still didn't work.
Finding the solution
Then I did some grepping and found the problem in the .lpi and fixed it and it worked.
Finally I went into the ray4laz repo and found -WM11 in the /package/ray4laz_simpleprj.pas and changed it there, recompiled the packages, reimported, started a new simple project and it built and ran the first time!
One last informational thing that is not ray4laz specific and is not a problem with this repo: when I build the raylib simple project I still get the error Error: -macosx_version_min has been renamed to -macos_version_min but it doesn't stop anything from working at all so its a red herring. Everything builds and runs perfectly even though it has that error. I'm trying to fix that in the fpc source, but if anyone complains about that in the future, its really not an issue for me even though it has a big red x in the output window.