lua-users home
lua-l archive

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


Il 19/09/2013 18:19, Philipp Janda ha scritto:
Am 19.09.2013 17:10 schröbte Francesco Santini:
My setup is the following: a program (that is provided to me as-is) is
dynamically loading a .so library (written by me) that contains the Lua
VM (linked dynamically, but I also tried statically). My .so file wants
to load a binary module (which, when loaded from command-line, works
fine).

At this point, the "require" fails with the error "unresolved symbol:
lua_gettop". Other modules give other lua-related unresolved symbols.
>
> <snip>
>
There is a glibc-specific dlopen-flag (man 3 dlopen):
RTLD_NOLOAD (since glibc 2.2)
     Don't load the library. This can be used to test if the library is
already resident (dlopen() returns NULL if it is not, or the library's
handle if it is resident). This flag can also be used to promote the
flags on a library that is already loaded. For example, a library that
was previously loaded with RTLD_LOCAL can be reopened with RTLD_NOLOAD |
RTLD_GLOBAL. This flag is not specified in POSIX.1-2001.

I don't know if this also works from within the dynamically loaded
library, but you can try (and tell us how it went) ...

Thank you Philipp for the great explanation, it was very informative. What you proposed eventually did not work (it seems that a library cannot call dlopen on itself) but it pointed me in the right directon.

What I did was to call dlopen("libluajit.so", RTLD_NOW | RTLD_GLOBAL) from within the library so that the lua symbols were loaded in the global namespace and therefore available for the subsequent modules.

Now everything works again and I didn't have to change anything in the modules!

Francesco