Statically compiled LuaJIT with dynamic modules on Windows

  • From: Paul K <paul@xxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 25 Nov 2013 14:03:46 -0800

Hi Mike,

I'm trying to get statically compiled LuaJIT working with dynamic
modules (linked against lua51.dll). I know about "don't do it", but I
have several reasons for pursuing this if I can get it to work.

The setup I have: (1) statically compiled LuaJIT, (2) a proxy DLL
(lua51.dll) that forwards requests to appropriate methods in LuaJIT
executable [1], (3) a dynamic module linked against lua51.dll (outside
of my control; I can't re-compile it).

For the proxy DLL to work I need to have the executable that exports
the same symbols as the DLL (for GetProcAddress to work) and this is
where I'm stuck. I got it working with Lua5.1 interpreter using the
following script:

dlltool --export-all --output-def lua.def lapi.o ldebug.o ldo.o
lstate.o lauxlib.o lbaselib.o ldblib.o linit.o liolib.o lmathlib.o
loadlib.o loslib.o lstrlib.o ltablib.o
dlltool --dllname lua.exe --def lua.def --output-lib liblua.a
dlltool --dllname lua.exe --output-exp lua.exp --def lua.def
gcc -g -o lua.exe -Wl,--base-file,lua.base lua.exp lua.o liblua.a
dlltool --dllname lua.exe --base-file lua.base --output-exp lua.exp
--def lua.def
gcc -g -o lua.exe lua.exp *.o

When I try something similar with LuaJIT (replacing the list on the
first line to get exported symbols and on the last line), I get
several undefined reference errors:

luajit.o:luajit.c:(.text+0xf9): undefined reference to `_imp__lua_sethook'
luajit.o:luajit.c:(.text+0x146): undefined reference to `_imp__luaL_where'
...

What's the proper method of getting this compiled statically with
exported symbols? I'm using mingw, but can also use VS (2008). Thank
you.

Paul.

[1] http://lua-users.org/wiki/LuaProxyDllFour

Other related posts: