stetre / moonglfw

Lua bindings for GLFW
Other
67 stars 13 forks source link

Fix compilation with musl libc (Alpine linux) #5

Closed sodomon2 closed 3 years ago

sodomon2 commented 3 years ago

replaced -I/usr/include/lua$(LUAVER) with pkg-config --cflags --libs lua$(LUAVER).

sodomon2 commented 3 years ago

@stetre this is the output of the command pkg-config --cflags --libs lua5.3

-I/usr/include/lua5.3 -L/usr/lib/lua5.3 -llua -lm

stetre commented 3 years ago

Please, try replacing the pkg-config line with the following and let me know if it works

INCDIR = -I/usr/include/lua$(LUAVER)
LIBDIR = -L/usr/lib/lua$(LUAVER)
sodomon2 commented 3 years ago

Ok, I tried it that way and it gives the same errors as without the pkg-conf.

user $ ldd src/moonglfw.so
    /lib/ld-musl-x86_64.so.1 (0x7f5309568000)
    libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f5309568000)
Error relocating src/moonglfw.so: lua_pcallk: symbol not found
Error relocating src/moonglfw.so: lua_touserdata: symbol not found
Error relocating src/moonglfw.so: lua_pushlightuserdata: symbol not found
Error relocating src/moonglfw.so: lua_getallocf: symbol not found
Error relocating src/moonglfw.so: luaL_ref: symbol not found
Error relocating src/moonglfw.so: lua_seti: symbol not found
Error relocating src/moonglfw.so: luaL_unref: symbol not found
Error relocating src/moonglfw.so: lua_gettop: symbol not found
Error relocating src/moonglfw.so: luaL_checkstack: symbol not found
Error relocating src/moonglfw.so: lua_tointegerx: symbol not found
Error relocating src/moonglfw.so: luaL_checklstring: symbol not found
Error relocating src/moonglfw.so: lua_pushnumber: symbol not found
Error relocating src/moonglfw.so: lua_setfield: symbol not found
Error relocating src/moonglfw.so: lua_pushvalue: symbol not found
Error relocating src/moonglfw.so: luaL_error: symbol not found
Error relocating src/moonglfw.so: lua_geti: symbol not found
Error relocating src/moonglfw.so: lua_settop: symbol not found
Error relocating src/moonglfw.so: lua_pushfstring: symbol not found
Error relocating src/moonglfw.so: luaL_checknumber: symbol not found
Error relocating src/moonglfw.so: lua_tolstring: symbol not found
Error relocating src/moonglfw.so: lua_type: symbol not found
Error relocating src/moonglfw.so: lua_pushboolean: symbol not found
Error relocating src/moonglfw.so: lua_settable: symbol not found
Error relocating src/moonglfw.so: lua_rawseti: symbol not found
Error relocating src/moonglfw.so: luaL_optlstring: symbol not found
Error relocating src/moonglfw.so: lua_isinteger: symbol not found
Error relocating src/moonglfw.so: lua_error: symbol not found
Error relocating src/moonglfw.so: lua_pushstring: symbol not found
Error relocating src/moonglfw.so: luaL_argerror: symbol not found
Error relocating src/moonglfw.so: luaL_checkinteger: symbol not found
Error relocating src/moonglfw.so: luaL_setfuncs: symbol not found
Error relocating src/moonglfw.so: lua_rawgeti: symbol not found
Error relocating src/moonglfw.so: luaL_optinteger: symbol not found
Error relocating src/moonglfw.so: luaL_len: symbol not found
Error relocating src/moonglfw.so: lua_toboolean: symbol not found
Error relocating src/moonglfw.so: lua_createtable: symbol not found
Error relocating src/moonglfw.so: lua_pushinteger: symbol not found
stetre commented 3 years ago

Does it work if you add also the following? (it should)

LIBS= -llua -lm
sodomon2 commented 3 years ago
LIBS= -llua -lm

With this it works, but link the library with lua5.1

stetre commented 3 years ago
LIBS= -llua -lm

With this it works, but link the library with lua5.1

Was it the same with your pkg-config fix? The above INCDIR, LIBDIR and LIBS definitions taken together are exactly the same as the pkg-config output.

sodomon2 commented 3 years ago

I have done it this way

INCDIR = -I/usr/include/lua$(LUAVER)
LIBDIR = -L/usr/lib/lua$(LUAVER) /usr/lib/liblua-$(LUAVER).so.0 -lm 

apparently it doesn't give errors when making the library

user $ ldd src/moonglfw.so
    /lib/ld-musl-x86_64.so.1 (0x7f4d66183000)
    liblua-5.3.so.0 => /usr/lib/liblua-5.3.so.0 (0x7f4d66133000)
    libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f4d66183000)
stetre commented 3 years ago

This makes more sense. The LIBDIR definition shouldn't be necessary, then, since the library is in the standard location /usr/lib . To sum up, the original Makefile should work by just adding the definition:

LIBS=/usr/lib/liblua-$(LUAVER).so.0 -lm 

Unfortunately this also break the compilation against lualib built from the official package (the linker doesn't like -llua because the official package does't compile with -fPIC).

As a temporary measure, I can add it and comment it out, so you would have to uncomment it after cloning. Is it ok for you?

sodomon2 commented 3 years ago

@stetre OH! sounds good to me

stetre commented 3 years ago

Done. Let me know if it works or not. Thank you.

sodomon2 commented 3 years ago

@stetre OH! yes it works :) now i will close this :)