E
E
Evgeny Ivanovich2019-09-09 02:33:45
Building projects
Evgeny Ivanovich, 2019-09-09 02:33:45

Library function not found?

In general, there is a game server garry's mod (source hl2) on Linux, according to the standard there is a modified lua5.1 library called lua_shared.so, despite the fact that it has changed the names of the library functions are the same, i.e. not changed. And so, there is a task to write a module that is loaded using the require function from the /lua/bin/ path. The library has two export functions, gmod13_open and gmod13_close. According to the φ standard, these functions are called with the machine's lua parameter lua_State. So I'm compiling the code

#ifdef _WIN32
#define DLL_EXPORT extern "C" __declspec( dllexport )
#else
#define DLL_EXPORT extern "C" __attribute__((visibility("default")))
#endif

extern "C"
{
  #include "lua.h"
  #include "lauxlib.h"
  #include "lualib.h"
}

static void lua_print(lua_State* L, const char* msg)
{
  lua_getglobal(L, "print");
  lua_pushstring(L, msg);
  lua_call(L, 1, 0);
}

static int lua_testfunction(lua_State* l)
{
  return 0;
}

static const  luaL_Reg module[] =
{
  {"TestFunction", lua_testfunction},
  {NULL, NULL}
};

DLL_EXPORT int gmod13_open(lua_State* L)
{
  lua_print(L, "-> ekau module loaded.");
  luaL_register(L, "ekau", module);
  return 0;
}

DLL_EXPORT int gmod13_close(lua_State* L)
{
  return 0;
}

With a shell script
#!/usr/bin/sh

LIBPATH=/home/independent/.steam/steam/steamapps/common/GarrysMod/garrysmod/lua/bin/
LUASHARED=/home/independent/.steam/steam/steamapps/common/GarrysMod/garrysmod/bin/

gcc -fPIC -m32 -I../gmod-module-base/include/ -I../lua-5.1.5/src/ main.cpp -shared -Wl,-soname,lua_shared.so,--no-undefined -DGMMODULE -o library -L$LUASHARED -l:lua_shared.so

mv library $LIBPATH'/gmsv_ekau_linux.dll'

I call the require function in the game with the "ekau" parameter and get the following error at the output
Couldn't load module library!
   1: (message = "Couldn't load module library!") [lua/gcompute/execution/local/gluaexecutioninstance.lua: 178]
   2: ("ekau", userdata: 0xc7467a38, "/home/independent/.steam/steam/steamapps/common/GarrysMod/garrysmod/lua/bin/gmsv_ekau_linux.dll: undefined symbol: lua_getfield", "Couldn't load module library!") [[C]: -1]
   3: xpcall (function (message)) [[C]: -1]
   4: Start (self = { GCompute.Execution.GLuaExecutionInstance: 0xc6a5a9f0 }) [lua/gcompute/execution/local/gluaexecutioninstance.lua: 173]
   5: CreateExecutionInstance (self = { GCompute.Execution.GLuaExecutionContext: 0xc69dcd30 }, code = "require \"ekau\"", sourceId = "@repl_0", instanceOptions = 6, callback = nil) [lua/gcompute/execution/executioncontext.lua: 56]
   6: HandleExecutionInstanceCreationRequest0 (self = { GCompute.Execution.RemoteExecutionContextHost: 0xc71158f0 }, connection = { GLib.Net.Connection: 0xcc50f580 }, inBuffer = { GLib.Net.Layer1.PinnedNetInBuffer: 0xc74a0b40 }) [lua/gcompute/execution/remote/remoteexecutioncontexthost.lua: 94]
   7: (self = { GCompute.Execution.RemoteExecutionContextHost: 0xc71158f0 }, connection = { GLib.Net.Connection: 0xcc50f580 }, inBuffer = { GLib.Net.Layer1.PinnedNetInBuffer: 0xc74a0b40 }) [lua/gcompute/execution/remote/remoteexecutioncontexthost.lua: 78]
   8: xpcall (GLib.Error) [[C]: -1]
   9: () [lua/glib/threading/thread.lua: 262]

Namely
undefined symbol: lua_getfield", "Couldn't load module library!"

Why writes that the function is not defined / found???? How to solve this problem, I'm worried for more than a day.
This, I believe, will show that the lua_shared.so library is loaded by the system
[email protected]:~$ lsof -p 8511 | grep lua_shared
hl2_linux 8511 independent  mem       REG               8,20     720238  667545 /home/independent/.steam/steam/steamapps/common/GarrysMod/garrysmod/bin/lua_shared.so

This will show that lua_getfield is in the lua_shared.so library
[email protected]:~/.steam/steam/steamapps/common/GarrysMod/garrysmod/bin$ nm -r lua_shared.so | grep lua_getfield
0004d190 T lua_getfield

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
D
dollar, 2019-09-09
@dollar

Well, it's lua_getglobaldefined via lua_getfield, so it turns out that the macro works, but the symbol itself doesn't.
Try playing with compilation flags like-Wl,-export-dynamic

J
jcmvbkbc, 2019-09-09
@jcmvbkbc

And why is there this in the gmsv_ekau_linux.dll assembly script: -Wl,-soname,lua_shared.so?

Q
q2zoff, 2019-09-10
@q27off

s/gmod13_open/ekau_luaopen/g

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question