NLua/KeraLua

Fails to load lua53 assembly when building with Mono.

c272 opened this issue · 9 comments

c272 commented

When using msbuild with a Release configuration on Mono, and attempting to call any KeraLua functions, the following exception is thrown:

System.DllNotFoundException: lua53 assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) KeraLua.NativeMethods.luaL_newstate()
  at KeraLua.Lua..ctor (System.Boolean openLibs) [0x00011] in <235b271fdb5246b0b6f5e31909b083cc>:0
  at NLua.Lua..ctor () [0x00011] in <d06f979493b246a991c622e6280dbc61>:0
  at BattleRoyaleBot.Battle_Royale.EventLoader.Load (System.String folderPath) [0x00074] in <9408c3b008d14a8b8db6a62f5648b1f0>:0
  at BattleRoyaleBot.Program.StartBot () [0x00113] in <9408c3b008d14a8b8db6a62f5648b1f0>:0

Not really sure what's going on, I assume the assembly is failing resolve, but I have the lua53.dll, liblua53.dylib and Kera/NLua .dlls inside the folder, as well as in the x64 and x86 folders.

I'm using .NET Framework 4.7.1, and Mono compiler version 6.8.0.123.

c272 commented

On closer inspection with DNSpy, looks like it's defaulting to the last "else" case in the preprocessor directive, just "lua53" (from NativeMethods.cs). This should still work, unsure why it's failing.

// Token: 0x0600010C RID: 268
[DllImport("lua53", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr lua_newstate(IntPtr allocFunction, IntPtr ud);

Are you using the version from NuGet ?
What OS ?

c272 commented

Turns out Mono is trying to look for the following paths for DLL maps:

lua53
liblua53
liblua53.so
/usr/lib/lua53
/usr/lib/liblua53
/usr/lib/liblua53.so

None of which exist by just installing the NuGet package.

c272 commented

I have found a solution, but it requires a little finnicky build work. Turns out Mono doesn't like you loading executables or position independant ones dynamically, so even if you include a "lua53" linux binary, it won't work.

To get it to function properly, you need to build a Lua shared object file (liblua53.so). The default Lua makefiles don't allow you to do this normally, so you have to modify them.

Here are the steps I took:

  1. Download the Lua source from the Lua download page.
  2. Replace /Makefile and /src/Makefile with the below two scripts to enable building .so files:

/Makefile:

# Makefile for installing Lua
# See doc/readme.html for installation and customization instructions.

# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================

# Your platform. See PLATS for possible values.
PLAT= none

# Lua version and release.
V= 5.3
R= $V.4

# Where to install. The installation starts in the src and doc directories,
# so take care if INSTALL_TOP is not an absolute path. See the local target.
# You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with
# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.
INSTALL_TOP= /usr/local
INSTALL_BIN= $(INSTALL_TOP)/bin
INSTALL_INC= $(INSTALL_TOP)/include
INSTALL_LIB= $(INSTALL_TOP)/lib
INSTALL_MAN= $(INSTALL_TOP)/man/man1
INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V
INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V

# How to install. If your install program does not support "-p", then
# you may have to run ranlib on the installed liblua.a.
INSTALL= install -p
INSTALL_EXEC= $(INSTALL) -m 0755
INSTALL_DATA= $(INSTALL) -m 0644
#
# If you don't have "install" you can use "cp" instead.
# INSTALL= cp -p
# INSTALL_EXEC= $(INSTALL)
# INSTALL_DATA= $(INSTALL)

# Other utilities.
MKDIR= mkdir -p
RM= rm -f

# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======

# Convenience platforms targets.
PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris

# What to install.
TO_BIN= lua luac
TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp
TO_LIB= liblua.a liblua.so.$(R)
TO_MAN= lua.1 luac.1



# Targets start here.
all:    $(PLAT)

$(PLATS) clean:
        cd src && $(MAKE) $@ V=$(V) R=$(R)

test:   dummy
        src/lua -v

install: dummy
        cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
        cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)
        cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
        cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
        cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
        ln -s $(INSTALL_LIB)/liblua.so.$(R) $(INSTALL_LIB)/liblua.so.$(V)
        ln -s $(INSTALL_LIB)/liblua.so.$(R) $(INSTALL_LIB)/liblua.so

uninstall:
        cd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN)
        cd src && cd $(INSTALL_INC) && $(RM) $(TO_INC)
        cd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB)
        cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN)

local:
        $(MAKE) install INSTALL_TOP=../install

none:
        @echo "Please do 'make PLATFORM' where PLATFORM is one of these:"
        @echo "   $(PLATS)"
        @echo "See doc/readme.html for complete instructions."

# make may get confused with test/ and install/
dummy:

# echo config parameters
echo:
        @cd src && $(MAKE) -s echo
        @echo "PLAT= $(PLAT)"
        @echo "V= $V"
        @echo "R= $R"
        @echo "TO_BIN= $(TO_BIN)"
        @echo "TO_INC= $(TO_INC)"
        @echo "TO_LIB= $(TO_LIB)"
        @echo "TO_MAN= $(TO_MAN)"
        @echo "INSTALL_TOP= $(INSTALL_TOP)"
        @echo "INSTALL_BIN= $(INSTALL_BIN)"
        @echo "INSTALL_INC= $(INSTALL_INC)"
        @echo "INSTALL_LIB= $(INSTALL_LIB)"
        @echo "INSTALL_MAN= $(INSTALL_MAN)"
        @echo "INSTALL_LMOD= $(INSTALL_LMOD)"
        @echo "INSTALL_CMOD= $(INSTALL_CMOD)"
        @echo "INSTALL_EXEC= $(INSTALL_EXEC)"
        @echo "INSTALL_DATA= $(INSTALL_DATA)"

# echo pkg-config data
pc:
        @echo "version=$R"
        @echo "prefix=$(INSTALL_TOP)"
        @echo "libdir=$(INSTALL_LIB)"
        @echo "includedir=$(INSTALL_INC)"

# list targets that do not create files (but not all makes understand .PHONY)
.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho

# (end of Makefile)

/src/Makefile:

# Makefile for installing Lua
# See doc/readme.html for installation and customization instructions.

# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================

# Your platform. See PLATS for possible values.
PLAT= none

# Lua version and release.
V= 5.3
R= $V.4

# Where to install. The installation starts in the src and doc directories,
# so take care if INSTALL_TOP is not an absolute path. See the local target.
# You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with
# LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.
INSTALL_TOP= /usr/local
INSTALL_BIN= $(INSTALL_TOP)/bin
INSTALL_INC= $(INSTALL_TOP)/include
INSTALL_LIB= $(INSTALL_TOP)/lib
INSTALL_MAN= $(INSTALL_TOP)/man/man1
INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V
INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V

# How to install. If your install program does not support "-p", then
# you may have to run ranlib on the installed liblua.a.
INSTALL= install -p
INSTALL_EXEC= $(INSTALL) -m 0755
INSTALL_DATA= $(INSTALL) -m 0644
#
# If you don't have "install" you can use "cp" instead.
# INSTALL= cp -p
# INSTALL_EXEC= $(INSTALL)
# INSTALL_DATA= $(INSTALL)

# Other utilities.
MKDIR= mkdir -p
RM= rm -f

# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======

# Convenience platforms targets.
PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris

# What to install.
TO_BIN= lua luac
TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp
TO_LIB= liblua.a liblua.so.$(R)
TO_MAN= lua.1 luac.1



# Targets start here.
all:    $(PLAT)

$(PLATS) clean:
        cd src && $(MAKE) $@ V=$(V) R=$(R)

test:   dummy
        src/lua -v

install: dummy
        cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
        cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)
        cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
        cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
        cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
        ln -s $(INSTALL_LIB)/liblua.so.$(R) $(INSTALL_LIB)/liblua.so.$(V)
        ln -s $(INSTALL_LIB)/liblua.so.$(R) $(INSTALL_LIB)/liblua.so

uninstall:
        cd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN)
        cd src && cd $(INSTALL_INC) && $(RM) $(TO_INC)
        cd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB)
        cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN)

local:
        $(MAKE) install INSTALL_TOP=../install

none:
        @echo "Please do 'make PLATFORM' where PLATFORM is one of these:"
        @echo "   $(PLATS)"
        @echo "See doc/readme.html for complete instructions."

# make may get confused with test/ and install/
dummy:

# echo config parameters
echo:
        @cd src && $(MAKE) -s echo
        @echo "PLAT= $(PLAT)"
        @echo "V= $V"
        @echo "R= $R"
        @echo "TO_BIN= $(TO_BIN)"
        @echo "TO_INC= $(TO_INC)"
        @echo "TO_LIB= $(TO_LIB)"
        @echo "TO_MAN= $(TO_MAN)"
        @echo "INSTALL_TOP= $(INSTALL_TOP)"
        @echo "INSTALL_BIN= $(INSTALL_BIN)"
        @echo "INSTALL_INC= $(INSTALL_INC)"
        @echo "INSTALL_LIB= $(INSTALL_LIB)"
        @echo "INSTALL_MAN= $(INSTALL_MAN)"
        @echo "INSTALL_LMOD= $(INSTALL_LMOD)"
        @echo "INSTALL_CMOD= $(INSTALL_CMOD)"
        @echo "INSTALL_EXEC= $(INSTALL_EXEC)"
        @echo "INSTALL_DATA= $(INSTALL_DATA)"

# echo pkg-config data
pc:
        @echo "version=$R"
        @echo "prefix=$(INSTALL_TOP)"
        @echo "libdir=$(INSTALL_LIB)"
        @echo "includedir=$(INSTALL_INC)"

# list targets that do not create files (but not all makes understand .PHONY)
.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho

# (end of Makefile)
root@vultr:~/bot/lua/lua-5.3.5# cat src/Makefile
# Makefile for building Lua
# See ../doc/readme.html for installation and customization instructions.

# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================

# Your platform. See PLATS for possible values.
PLAT= none

CC= gcc -std=gnu99
CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS) -fPIC
LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
LIBS= -lm $(SYSLIBS) $(MYLIBS)

AR= ar rcu
RANLIB= ranlib
RM= rm -f

SYSCFLAGS=
SYSLDFLAGS=
SYSLIBS=

MYCFLAGS=
MYLDFLAGS=
MYLIBS=
MYOBJS=

# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======

PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris

LUA_A=  liblua.a
LUA_SO= liblua.so
CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
        lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \
        ltm.o lundump.o lvm.o lzio.o
LIB_O=  lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \
        lmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o
BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)

LUA_T=  lua
LUA_O=  lua.o

LUAC_T= luac
LUAC_O= luac.o

ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O)
ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) $(LUA_SO)
ALL_A= $(LUA_A)

# Targets start here.
default: $(PLAT)

all:    $(ALL_T)

o:      $(ALL_O)

a:      $(ALL_A)

$(LUA_A): $(BASE_O)
        $(AR) $@ $(BASE_O)
        $(RANLIB) $@

$(LUA_SO): $(CORE_O) $(LIB_O)
        $(CC) -shared -ldl -Wl,-soname,$(LUA_SO).$(V) -o $@.$(R) $? -lm $(MYLDFLAGS)
        ln -sf $(LUA_SO).$(R) $(LUA_SO).$(V)
        ln -sf $(LUA_SO).$(R) $(LUA_SO)

$(LUA_T): $(LUA_O) $(LUA_A)
        $(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)

$(LUAC_T): $(LUAC_O) $(LUA_A)
        $(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)

clean:
        $(RM) $(ALL_T) $(ALL_O)

depend:
        @$(CC) $(CFLAGS) -MM l*.c

echo:
        @echo "PLAT= $(PLAT)"
        @echo "CC= $(CC)"
        @echo "CFLAGS= $(CFLAGS)"
        @echo "LDFLAGS= $(SYSLDFLAGS)"
        @echo "LIBS= $(LIBS)"
        @echo "AR= $(AR)"
        @echo "RANLIB= $(RANLIB)"
        @echo "RM= $(RM)"

# Convenience targets for popular platforms
ALL= all

none:
        @echo "Please do 'make PLATFORM' where PLATFORM is one of these:"
        @echo "   $(PLATS)"

aix:
        $(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall"

bsd:
        $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E"

c89:
        $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_C89" CC="gcc -std=c89"
        @echo ''
        @echo '*** C89 does not guarantee 64-bit integers for Lua.'
        @echo ''


freebsd:
        $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE -I/usr/include/edit" SYSLIBS="-Wl,-E -ledit" CC="cc"

generic: $(ALL)

linux:
        $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline"

macosx:
        $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline"

mingw:
        $(MAKE) "LUA_A=lua53.dll" "LUA_T=lua.exe" \
        "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \
        "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe
        $(MAKE) "LUAC_T=luac.exe" luac.exe

posix:
        $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX"

solaris:
        $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT" SYSLIBS="-ldl"

# list targets that do not create files (but not all makes understand .PHONY)
.PHONY: all $(PLATS) default o a clean depend echo none

# DO NOT DELETE

lapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
 lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \
 ltable.h lundump.h lvm.h
lauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h
lbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
lbitlib.o: lbitlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
lcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \
 llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \
 ldo.h lgc.h lstring.h ltable.h lvm.h
lcorolib.o: lcorolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
lctype.o: lctype.c lprefix.h lctype.h lua.h luaconf.h llimits.h
ldblib.o: ldblib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
ldebug.o: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
 lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \
 ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h
ldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
 lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \
 lparser.h lstring.h ltable.h lundump.h lvm.h
ldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \
 ltm.h lzio.h lmem.h lundump.h
lfunc.o: lfunc.c lprefix.h lua.h luaconf.h lfunc.h lobject.h llimits.h \
 lgc.h lstate.h ltm.h lzio.h lmem.h
lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
 llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h
liolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \
 lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \
 lstring.h ltable.h
lmathlib.o: lmathlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
lmem.o: lmem.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
 llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h
loadlib.o: loadlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
lobject.o: lobject.c lprefix.h lua.h luaconf.h lctype.h llimits.h \
 ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \
 lvm.h
lopcodes.o: lopcodes.c lprefix.h lopcodes.h llimits.h lua.h luaconf.h
loslib.o: loslib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
lparser.o: lparser.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \
 llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \
 ldo.h lfunc.h lstring.h lgc.h ltable.h
lstate.o: lstate.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
 lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \
 lstring.h ltable.h
lstring.o: lstring.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \
 lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h
lstrlib.o: lstrlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
ltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
 llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h
ltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
ltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
 llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h ltable.h lvm.h
lua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
luac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h lobject.h llimits.h \
 lstate.h ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h
lundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \
 lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \
 lundump.h
lutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
lvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
 llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \
 ltable.h lvm.h
lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \
 lobject.h ltm.h lzio.h

# (end of Makefile)
  1. Use make linux to build the .so files. You should now see liblua.so inside your src/ folder.
  2. Copy liblua.so into your program's directory, and rename it "liblua53.so". This will differ depending on the Lua version you're using, so it might be liblua54.so, liblua52.so etc.
  3. Run your program! Mono should detect the shared object library now. If it doesn't, make sure you have a resolved DLL path by using this page as a reference.

Sources:
https://git.archlinux.org/svntogit/packages.git/tree/trunk/liblua.so.patch?h=packages/lua
https://github.com/NLua/KeraLua/blob/master/src/NativeMethods.cs
https://gist.github.com/dcarrith/6095183b8dc60c909779
https://gist.github.com/dcarrith/899047f3a2d603b25a58

c272 commented

@viniciusjarina Ubuntu Server, 18.xx. And yes, I'm using the NuGet version, I'm not building it myself.

Why do you need to build Lua from the source? The nuget already contain a x64 Linux so. Are you targeting arm?

c272 commented

Oh, my bad 😅. There is indeed a .so in /x64, but Mono can't find it since it's not inclined to search in there unless you point at it as another dependency path.

You could fix the issue without building source, you would just need to cp ./x64/liblua53.so ./liblua53.so.

You don't need to manually copy the .so the .target will copy the library to the output folder 😕

For instance take a look at the output of NLua build at travis.

https://travis-ci.org/github/NLua/NLua/builds/694137531

CopyOutOfDateSourceItemsToOutputDirectory:

  Copying file from "/home/travis/.nuget/packages/keralua/1.2.1/runtimes/win-x64/native/lua54.dll" to "/home/travis/build/NLua/NLua/lib/Release/net45/lua54.dll".

  Copying file from "/home/travis/.nuget/packages/keralua/1.2.1/runtimes/osx/native/liblua54.dylib" to "/home/travis/build/NLua/NLua/lib/Release/net45/liblua54.dylib".

  Copying file from "/home/travis/.nuget/packages/keralua/1.2.1/runtimes/linux-x64/native/liblua54.so" to "/home/travis/build/NLua/NLua/lib/Release/net45/liblua54.so".

  Creating directory "../../lib/Release/net45/x86".

  Copying file from "/home/travis/.nuget/packages/keralua/1.2.1/runtimes/win-x86/native/lua54.dll" 
c272 commented

This is what I'm saying, it does put it into /Release/net45 or /Release/x64, but Mono doesn't look into those directories by default.

It only looks into /Release, where the executable actually is, at least for me.