lem icon indicating copy to clipboard operation
lem copied to clipboard

LEM is not loading on OSX (M1)

Open cianoc opened this issue 9 months ago • 8 comments

I get the following error: debugger invoked on a CFFI:LOAD-FOREIGN-LIBRARY-ERROR in thread #<THREAD "main thread" RUNNING {700A420003}>: Unable to load foreign library (LIBSDL2_IMAGE-2.0.0.DYLIB-474). Error opening shared object "/Applications/lem.app/Contents/Frameworks/libSDL2_image-2.0.0.dylib": dlopen(/Applications/lem.app/Contents/Frameworks/libSDL2_image-2.0.0.dylib, 0x000A): Library not loaded: /opt/homebrew/opt/libavif/lib/libavif.15.dylib Referenced from: <075C01CF-54D6-365E-BB52-CB5554ED1622> /Applications/lem.app/Contents/Frameworks/libSDL2_image-2.0.0.dylib Reason: tried: '/opt/homebrew/opt/libavif/lib/libavif.15.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/libavif/lib/libavif.15.dylib' (no such file), '/opt/homebrew/opt/libavif/lib/libavif.15.dylib' (no such file), '/usr/local/lib/libavif.15.dylib' (no such file), '/usr/lib/libavif.15.dylib' (no such file, not in dyld cache), '/opt/homebrew/Cellar/libavif/1.0.1/lib/libavif.15.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/libavif/1.0.1/lib/libavif.15.dylib' (no such file), '/opt/homebrew/Cellar/libavif/1.0.1/lib/libavif.15.dylib' (no such file), '/usr/local/lib/libavif.15.dylib' (no such file), '/usr/lib/libavif.15.dylib' (no such file, not in dyld cache).

The current version of homebrew has libavif.16. I suspect the problem here is that LEM is shipped with its own version of SDL, but this has dependencies upon homebrew, and whenever libraries get updated then it is going to fail.

Probably the best two solutions are either:

  1. Use the version of SDL that is shipped with homebrew (Which I thought was happening)
  2. Provide SDL2 libraries that don't have any external dependencies.

cianoc avatar Oct 11 '23 19:10 cianoc

This is using the official installer.

cianoc avatar Oct 11 '23 19:10 cianoc

I think I'm the one working on this but unfortunately haven't had time to update the installers nor write a homebrew solution :-(

seanfarley avatar Oct 16 '23 19:10 seanfarley

I'd like to strongly suggest option 2 above. Requiring homebrew installation of external dependencies for an application bundle would be quite annoying, especially for those that don't prefer homebrew such as myself.

I'm having similar issues getting this going, though the particular dylib is different. I started down the path of trying to change the load path of the various libraries but that opens up a whole can of code signing worms that I've yet to resolve. All because I don't use homebrew and don't want to install it.

I'd be happy to lend a hand on this but I didn't find any Makefiles, scripts or other information on building the app bundle.

sugarthc avatar Nov 12 '23 00:11 sugarthc

I was looking at this a bit more and there's pretty much no hope that this application bundle can run standalone (which I believe it should). The bundle itself contains these dylibs:

$ ls -1 arm64/lem.app/Contents/Frameworks/ libSDL2-2.0.0.dylib libSDL2_image-2.0.0.dylib libSDL2_ttf-2.0.0.dylib libasyncprocess.so libpng16.16.dylib

looking at the load commands for each of these shows homebrew dependencies that are not bundled:

$ for lib in arm64/lem.app/Contents/Frameworks/*; do echo "$lib:"; otool -l $lib | grep -C2 LC_LOAD_DYLIB | grep name | grep homebrew; done arm64/lem.app/Contents/Frameworks/libSDL2-2.0.0.dylib: arm64/lem.app/Contents/Frameworks/libSDL2_image-2.0.0.dylib: name /opt/homebrew/opt/libpng/lib/libpng16.16.dylib (offset 24) name /opt/homebrew/opt/jpeg-xl/lib/libjxl.0.8.dylib (offset 24) name /opt/homebrew/opt/jpeg-turbo/lib/libjpeg.8.dylib (offset 24) name /opt/homebrew/opt/libtiff/lib/libtiff.6.dylib (offset 24) name /opt/homebrew/opt/libavif/lib/libavif.15.dylib (offset 24) name /opt/homebrew/opt/webp/lib/libwebp.7.dylib (offset 24) name /opt/homebrew/opt/webp/lib/libsharpyuv.0.dylib (offset 24) name /opt/homebrew/opt/sdl2/lib/libSDL2-2.0.0.dylib (offset 24) arm64/lem.app/Contents/Frameworks/libSDL2_ttf-2.0.0.dylib: name /opt/homebrew/opt/freetype/lib/libfreetype.6.dylib (offset 24) name /opt/homebrew/opt/harfbuzz/lib/libharfbuzz.0.dylib (offset 24) name /opt/homebrew/opt/sdl2/lib/libSDL2-2.0.0.dylib (offset 24) arm64/lem.app/Contents/Frameworks/libasyncprocess.so: arm64/lem.app/Contents/Frameworks/libpng16.16.dylib:

Any of those dylibs could also have dependencies but since I don't have them installed I have no idea. If these were bundled then it should be a simple matter of running install_name_tool to change the load path for each dependent dylib and then re-sign the loading dylibs. I can't confirm this because I'm too lazy to install these libraries (and their crap-ton of unnecessary build-time dependencies), which is why I was looking for an application bundle in the first place.

sugarthc avatar Nov 14 '23 02:11 sugarthc

It's possible; just don't use the libraries install by Homebrew :-) There's a version I made for Intel macs here:

https://github.com/seanfarley/lem/releases

I just haven't had the time to put this all into a script and make sure rpath works correctly (instead of having to re-sign everything)

seanfarley avatar Nov 14 '23 23:11 seanfarley

Understood. I was neither clear nor precise in my last post. What I should have said is that this has no hope of running standalone as currently bundled. It can be run by anyone downloading it but they will have to provide the missing dependencies, either via homebrew or other means. If homebrew then nothing further need be done. If via other means then the load path and signing shenanigans noted above must be done.

It is my hope (and I'm willing to assist) that a bundle can be produced for download that does not have these external dependencies.

sugarthc avatar Nov 15 '23 00:11 sugarthc

Would it be possible to be installed from scratch? https://lem-project.github.io/installation/ncurses/macos/#installation-from-scratch

Sasanidas avatar Dec 07 '23 14:12 Sasanidas

@Sasanidas Confirmed. I just installed from that link.

Screenshot 2024-01-26 at 8 41 46 AM

mjstahl avatar Jan 26 '24 13:01 mjstahl