[Solved] Löve segfaults on OS X when loading dylibs
Posted: Fri Jul 30, 2021 7:18 pm
TL;DR: Pull the "Lua" file buried in , use that to replace the "libluajit.a".
Or, if you don't want to recompile: First make sure that your dylib file loads fine with the standard luajit distribution. Then replace the "Lua" file buried in with "libluajit.dylib" (but rename it to "Lua", without filename extension).
----------------------------------------------------------------------------------
After some work to pin down the problem, I made a minimal example for this.
I wrote a small C library, almost a direct copy of the example in the book Programming in Lua.
I compiled this with "liblua.a" of version 5.1.4, generating the file "hw.dylib", as provided in the attachment.
Next, a miniature lua script ("main.lua") in the same directory:
Run with the standard distribution of lua, it gives the correct result 0.8414709848079. However, starting love at this directory resulted in a Segmentation Fault. Below is a section of the crash report. I will post the full report if that is needed.
I am using the newest version of Love, 11.3. I started Love using the commandline (PathToLoveApplication)/Contents/MacOS/love.
Can anyone provide a clue to why this is happening, and a pointer to some possible solutions? Any help is appreciated!
Although it works, I haven't yet investigated further. I think the answer lies in the makefile in https://github.com/slime73/love-apple-dependencies.
Code: Select all
love.app/Contents/Framework/Lua.framework/Versions/A/Lua
Or, if you don't want to recompile: First make sure that your dylib file loads fine with the standard luajit distribution. Then replace the "Lua" file buried in
Code: Select all
love.app/Contents/Framework/Lua.framework/Versions/A/Lua
----------------------------------------------------------------------------------
After some work to pin down the problem, I made a minimal example for this.
I wrote a small C library, almost a direct copy of the example in the book Programming in Lua.
Code: Select all
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
#include <math.h>
static int l_sin (lua_State *L) {
double d = luaL_checknumber(L, 1); /* get argument */
lua_pushnumber(L, sin(d)); /* push result */
return 1; /* number of results */
}
static const struct luaL_reg mylib [] = {
{"sin", l_sin},
{NULL, NULL} /* sentinel */
};
int luaopen_mylib (lua_State *L) {
luaL_openlib(L, "mylib", mylib, 0);
return 1;
}
Next, a miniature lua script ("main.lua") in the same directory:
Code: Select all
l = package.loadlib("hw.dylib", "luaopen_mylib")
a = l()
print(a.sin(1))
Code: Select all
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 hw.dylib 0x0000000008a36aa3 lua_pushvalue + 195
1 hw.dylib 0x0000000008a4f10c luaL_findtable + 28
2 hw.dylib 0x0000000008a4efcb luaL_openlib + 91
3 hw.dylib 0x0000000008a362c5 luaopen_mylib + 37
4 LuaJIT.LuaJIT 0x0000000101f8be56 0x101f89000 + 11862
Can anyone provide a clue to why this is happening, and a pointer to some possible solutions? Any help is appreciated!
Although it works, I haven't yet investigated further. I think the answer lies in the makefile in https://github.com/slime73/love-apple-dependencies.