luajit shared library and executable all in one (linux)

  • From: Cosmin Apreutesei <cosmin.apreutesei@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 4 Nov 2014 19:35:19 +0200

Hi,

I want to make a luajit executable in linux x64 that has both Lua and
C modules bundled in.

The problem is that if I link the final exe with -shared, I can dlopen
the exe but can't run it (it segfaults). OTOH if I don't link with
-shared, I can run the exe, but can't dlopen it (I get "cannot
dynamically load executable"). Luajit can't require() the bundled
module either, probably because dlsym(NULL, symbol) doesn't work
either, even though the symbols are present.

I realize this is a gcc/ELF question and not luajit specifc, but is
`luajit -b` supposed to work on linux at all? If yes, does anyone know
how to build an exe to support that option?

Thanks,
Cosmin.

Other related posts: