lua-users home
lua-l archive

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


On 23.11.2013 06:04, Philipp Janda wrote:
Am 22.11.2013 21:56 schröbte Bernd Eggink:
On 22.11.2013 10:47, Philipp Janda wrote:

The next most likely reason is that the vim executable doesn't re-export
the Lua API functions because liblua was linked statically, and the
`-Wl,-E` flag was missing. AFAICT, linking dynamically
(`--enable-luainterp=dynamic`) should work because `RTLD_GLOBAL` is used
when loading liblua in this case ...

With --enable-luainterp=dynamic I get:

   E370: Could not load library liblua.so
   Lua library cannot be loaded.

Which isn't really suprising as I don't have a liblua.so. Unfortunately
my C knowledge has vastly faded away, so let me ask a stupid question:
The Linux Makefiles provided with the Lua sources automatically create a
static liblua.a on Linux, is that correct? If it is correct, I wonder
why the readme says:

Correct.


"We strongly recommend that you enable dynamic loading in src/luaconf.h.
This is done automatically for all platforms listed..."

You can use a static liblua.a and still enable dynamic loading of C
extension modules like e.g. luaposix on some (most?) platforms. The
problem is that the main program (e.g. the lua interpreter) needs access
to the Lua API functions, C extension modules need access as well, and
you must ensure that both are using the same set (so you can't link both
the lua interpreter and the extension modules to the static `liblua.a`,
or you will have multiple copies). You can do that by

a) linking the main program and the extension modules to the shared
liblua. Shared libraries are loaded only once per process. This is the
default on Windows.
b) linking the Lua API functions statically to the main program and
letting the main program re-export those functions to the extension
modules. This is the default on Linux/*BSD and uses the `-Wl,-E` linker
flag.
c) loading liblua.so in the main program using the `RTLD_GLOBAL` flag,
which re-exports the Lua API functions to extension modules. This is
what vim does on Unixes with `--enable-luainterp=dynamic`.


On Linux you can try (in Lua's `src` directory):

     make clean liblua.so SYSCFLAGS="-DLUA_USE_LINUX -fpic"
SYSLDFLAGS="-shared -Wl,--whole-archive" SYSLIBS="-ldl
-Wl,--no-whole-archive" LUA_T=liblua.so LUA_O=""

Philipp,
thanks a lot, that works perfectly!

I think this very good explanation should be added to the source distribution's readme. It's certainly of general interest, and I'm probably not the only one who has difficulties figuring that out by himself.

Regards,
Bernd
--
http://sudrala.de