How to integrate LuaJIT with LuaRocks on Windows?

I downloaded the LuaJIT source and compiled it with msvc120.dll (VS 2013 x64). When I run it from the command line, I have no problem executing some basic lua. Now the LuaJIT installation guide mentions moving luajit.exe and lua51.dll to their own folder. From there it says that it creates a lua folder and under that jit folder with the src / jit content moving under the newly created jit folder.

From my understanding, my folder should look like and contain:

/ lua
   / jit
       [rest of jit files]

Is this correct or am I missing files?

Now after I built my luajit I tried to hook it up to my luarocks to act like my interpreter using

install.bat /LUA C:\LuaJIT\2.0.3\[folder with above content]


However, this cannot find the header files. Then I copied the header files into the folder above and that started it, but I can never get anything to compile it when pointed to LuaJIT. Edit . The error I am getting is the following:

C: \ LuaJIT \ 2.0.3 \ bin \ lua51.dll: fatal error LNK1107: invalid or corrupt file: cannot read at 0x2D0

Error: Failed installing dependency: - Build error: Failed compiling module lfs.dll

Is the correct way to handle this by just pointing to my lua binaries and from there use LuaJIT to run my files or am I doing something wrong with the LuaJIT and luarocks hookup? The first one seems to work for the most part, since I only ran into one problem compiling the library, lua-cjson.


source to share

1 answer

I faced the same problem, but they found a solution right here:

I knew that for "linking a DLL statically" there is a so-called "export" .lib file that is passed to the linker (not the DLL itself).

So, for example, when compiling, LuaRocks did this:

cl /nologo /MD /O2 -c -Fosrc/mime.obj -ID:/LuaJIT-2.0.4/include/ src/mime.c -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DNDEBUG -DLUASOCKET_API=__declspec(dllexport) -DMIME_API=__declspec(dllexport) mime.c
link -dll -def:core.def -out:mime/core.dll D:/LuaJIT-2.0.4/bin/lua51.dll src/mime.obj


My LuaJIT was compiled from the source to D:\LuaJIT-2.0.4\src

, but I have made two folders D:\LuaJIT-2.0.4\include

with all the *.h

files copied from src

and D:\LuaJIT-2.0.4\bin

to luajit.exe

, lua51.dll

and then later lua51.exp

, and lua51.lib

. Another mistake, but it was the correct track.


Now check where your LuaRocks settings are located:

luarocks.bat help


Scroll down to a section, for example:

    Lua version: 5.1
    Configuration files:
            System: D:/luarocks/config-5.1.lua (ok)
            User  : (... snip ...)


Edit the system config file, namely:

variables = {
    LUALIB = 'lua51.dll' 



should be .lib

. If your export library is next to the DLL you just need to change to:

variables = {
    LUALIB = 'lua51.lib' -- here!



And now:

luarocks.bat install luasocket
link -dll -def:core.def -out:socket/core.dll D:/LuaJIT-2.0.4/bin/lua51.lib src/luasocket.obj (...)
luasocket 3.0rc1-2 is now built and installed in D:\luarocks\systree (license: MIT)


Notice the first argument passed to the linker.



All Articles