Answer the question
In order to leave comments, you need to log in
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;
}
#!/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'
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]
undefined symbol: lua_getfield", "Couldn't load module library!"
[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
[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
Well, it's lua_getglobal
defined 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
And why is there this in the gmsv_ekau_linux.dll assembly script: -Wl,-soname,lua_shared.so
?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question