lua-users home
lua-l archive

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


What is the recommended way to address the following use case:

* I am creating an executable which uses Lua to provide some scripting
support.
* I am using `luaL_openlibs` to load the Lua standard libraries.
* I am not loading any other ("non-standard") C-modules.
* I do load pure some Lua modules though.
* I am statically linking this executable, completely avoiding the use of
any shared libraries.

Simply adding `-static` in the linking flags, together with `-llua` and
`-lm` doesn't work, since `luaL_openlibs()` calls `dlopen`...

Linking with `-static` and `-ldl` works, but gives a linker warning: Using
'dlopen' in statically linked applications requires at runtime the shared
libraries from the glibc version used for linking

Which makes sense, I guess; if I load a dynamic library it will dynamically
load glibc, and things will get messy if that glibc is different from the
static glibc linked to the rest of the executable.

At any rate, even if this linker error was not an issue, the goal is to
create a completely static executable, without any dynamic dependencies, so
how to ensure `dlopen` works is not the issue I'm trying to solve.

The question is, instead, how do I avoid the call of `dlopen` in the first
place?

I have seen some old threads discussing this issue (or, at least, something
very close to it).
One direction was building Lua in a non-standard way (tweaking the Makefile,
tweaking the source code...). For example:

    make clean ansi CFLAGS='-ULUA_DL_DLOPEN'

I haven't investigated this direction yet, because it implies the project
can no longer be built with the "standard" Lua installation on the system.
That means that just listing Lua as a dependency would not be sufficient for
allowing the project to compile.

An obvious workaround is to include a complete Lua copy inside the project's
source tree - that would be ~1M of additional sources...

Is this the recommended practice for this use case, or is there a better
way?




--
View this message in context: http://lua.2524044.n2.nabble.com/Statically-linked-executables-tp7678758.html
Sent from the Lua-l mailing list archive at Nabble.com.