lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

It was thus said that the Great Peter Hickman once stated:
> Well I have the error now and it is a bit of an issue. First some set up
> The C wrapper
> #include <lauxlib.h>
> #include <lua.h>
> #include <lualib.h>
> int main(int argc, char **argv) {
>   const char *error;
>   lua_State *L = luaL_newstate();
>   luaL_openlibs(L);
>   if (luaL_dofile(L, "here/boot.lua") == LUA_OK) {
>     lua_pop(L, lua_gettop(L));
>   } else {
>     error = lua_tostring(L, -1);
>     puts(error);
>   }
>   lua_close(L);
>   return 0;
> }
> is compiled with
> cc -o here.Linux.x86_64 boot.c -Wall -Werror -fPIC -ansi -static -O3
> -DLUA_C89_NUMBERS -I/usr/include/lua5.3/ -llua5.3 -lm -ldl
> Which issues only 1 warning
> /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/liblua5.3.a(loadlib.o):
> In function `lookforfunc':
> (.text+0x596): warning: Using 'dlopen' in statically linked applications
> requires at runtime the shared libraries from the glibc version used for
> linking

  Static linking on Linux is not an easy thing anymore.  There's too much in
the C runtime (libc) that unfortunately relies upon dynamic linking (and I
don't think that will change any time soon---one of the previous maintainers
of libc practically refused to support static linking).

> There is only 1 version of lua on this computer, 5.3, and if I run the
> script from the shell
> $ lua5.3 here/boot.lua
> It works just fine, if I run the compiled version
> $ ./here.Linux.x86_64
> here/boot.lua:31: ./here/lib/socket/ undefined symbol: lua_gettop
> But the symbol is there
> $ nm ./here/lib/socket/ | grep lua_gettop
>                  U lua_gettop

  That does not mean the symbol is there---it means the symbol is not
defined in the current executable and needs to be resolved at runtime.

> Now my googling seems to say that luasocket is probably not being compiled
> in a way that exports the symbols correctly but the posts I've found are
> focused on lua <-> rust / python bridges and older versions of lua, 5.1

  When I compile your program on Linux without the "-static" options and
with a boot.lua that loads a C-based Lua module, it loads.  If I try
compiling with the "-static" option, I get a similar error you do.

  First question---what exactly are you attempting to do?  It's hard to see
what you want from your examples----the sample code hardcodes a script, so
are you trying to avoid having the user know the script to run?  Are you
trying to make a stand alone executable?  Knowing more context about what
you are trying to do will help.