|
On 6/27/2017 12:13 PM, Roberto Ierusalimschy wrote:
[...] Simply adding `-static` in the linking flags, together with `-llua` and `-lm` doesn't work, since `luaL_openlibs()` calls `dlopen`... [...] The question is, instead, how do I avoid the call of `dlopen` in the first place?Just a small correction, for the records: Lua never *calls* 'dlopen' by itself. In particular, 'luaL_openlibs' does not call 'dlopen'. Lua only calls 'dlopen' if the script calls 'require' (and 'require' finds an appropriate file in the C path) or if the script calls 'package.loadlib'. (Of course, that does not elliminate the fact that Lua has to be linked to the dlopen library with -ldl, therefore causing the problems you are relating.) -- Roberto
You could always provide a set of stubbed entry points instead of -ldl. If your stubbed version of dlopen() returns NULL then require will give up on all dynamically loaded C modules, but will otherwise continue to work with pure Lua modules. You might want to also empty (or significantly reduce) package.cpath.
Something like this (untested) might be enough: #include <dlfcn.h> void *dlopen(const char *filename, int flag) { return NULL; } char *dlerror(void) { return "libdl not implemented"; } void *dlsym(void *handle, const char *symbol) { return NULL; } int dlclose(void *handle) { return 0;Note that you can provide C modules that are also statically linked into your program by listing them in package.preload where require will look for them before attempting to use dlopen() to get them from a DLL or .so.
-- Ross Berteig Ross@CheshireEng.com Cheshire Engineering Corp. http://www.CheshireEng.com/ +1 626 303 1602