Re: luajit binary linking dynamically to libluajit.so on linux and osx

  • From: Mike Pall <mike-1403@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 13 Mar 2014 21:03:33 +0100

Cosmin Apreutesei wrote:
> On linux and osx, luajit is built statically. Can it be made to link
> dynamically to libluajit.so|.dylib so that the binary is smaller? If
> so, how?

make BUILDMODE=dynamic

> And, is there any downside to it?

The binary can't be run without installing it. And the .so is
bigger (and the C parts less efficient) than the luajit.c code
plus the non-PIC VM code.

[Note that it doesn't matter where the shared code segments come
from (.so or executable) -- they are shared across processes in
either case.]

> Also, I'm not sure if it's ok for Lua/C libraries to be linked against
> libluajit.dylib since that's not the running Lua runtime (even if it's
> ok, doesn't that mean that the luajit binary is loaded in memory
> twice, once from luajit and once from libluajit.dylib?)

Lua/C modules on POSIX systems must NOT be linked against a
library that contains a Lua or LuaJIT VM. The executable either
contains the VM or it loads the VM from a shared library. The
modules are loaded later on and access the VM via global symbols.

--Mike

Other related posts: