LuaJIT is only distributed as a source package. This page explains how to build and install LuaJIT with different operating systems and C compilers.
For the impatient (on POSIX systems):
make && sudo make install
LuaJIT currently builds out-of-the box on all popular x86 or x64 systems (Linux, Windows, OSX etc.).
Configuring LuaJIT
The standard configuration should work fine for most installations. Usually there is no need to tweak the settings. The following files hold all user-configurable settings:
- src/luaconf.h sets some configuration variables.
- Makefile has settings for installing LuaJIT (POSIX only).
- src/Makefile has settings for compiling LuaJIT under POSIX, MinGW and Cygwin.
- src/msvcbuild.bat has settings for compiling LuaJIT with MSVC.
Please read the instructions given in these files, before changing any settings.
POSIX Systems (Linux, OSX, *BSD etc.)
Prerequisites
Depending on your distribution, you may need to install a package for GCC (GCC 3.4 or later required), the development headers and/or a complete SDK. E.g. on a current Debian/Ubuntu, install libc6-dev with the package manager.
Download the current source package (pick the .tar.gz), if you haven't already done so. Move it to a directory of your choice, open a terminal window and change to this directory. Now unpack the archive and change to the newly created directory:
tar zxf LuaJIT-2.0.0-beta2.tar.gz cd LuaJIT-2.0.0-beta2
Building LuaJIT
The supplied Makefiles try to auto-detect the settings needed for your operating system and your compiler. They need to be run with GNU Make, which is probably the default on your system, anyway. Simply run:
make
This always builds a native x86 or x64 binary, depending on your OS.
By default modules are only searched under the prefix /usr/local. You can add an extra prefix to the search paths by appending the PREFIX option, e.g.:
make PREFIX=/home/myself/lj2
Note for OSX: MACOSX_DEPLOYMENT_TARGET is set to 10.4 in src/Makefile. Change it, if you want to build on an older version.
Installing LuaJIT
The top-level Makefile installs LuaJIT by default under /usr/local, i.e. the executable ends up in /usr/local/bin and so on. You need root privileges to write to this path. So, assuming sudo is installed on your system, run the following command and enter your sudo password:
sudo make install
Otherwise specify the directory prefix as an absolute path, e.g.:
make install PREFIX=/home/myself/lj2
Obviously the prefixes given during build and installation need to be the same.
Note: to avoid overwriting a previous version, the beta test releases only install the LuaJIT executable under the versioned name (i.e. luajit-2.0.0-beta2). You probably want to create a symlink for convenience, with a command like this:
sudo ln -sf luajit-2.0.0-beta2 /usr/local/bin/luajit
Windows Systems
Prerequisites
Either install one of the open source SDKs (» MinGW or » Cygwin), which come with a modified GCC plus the required development headers.
Or install Microsoft's Visual C++ (MSVC). The freely downloadable » Express Edition works just fine, but only contains an x86 compiler.
The freely downloadable » Windows SDK only comes with command line tools, but this is all you need to build LuaJIT. It contains x86 and x64 compilers.
Next, download the source package and unpack it using an archive manager (e.g. the Windows Explorer) to a directory of your choice.
Building with MSVC
Open a "Visual Studio .NET Command Prompt", cd to the directory where you've unpacked the sources and run these commands:
cd src msvcbuild
Then follow the installation instructions below.
Building with the Windows SDK
Open a "Windows SDK Command Shell" and select the x86 compiler:
setenv /release /x86
Or select the x64 compiler:
setenv /release /x64
Then cd to the directory where you've unpacked the sources and run these commands:
cd src msvcbuild
Then follow the installation instructions below.
Building with MinGW or Cygwin
Open a command prompt window and make sure the MinGW or Cygwin programs are in your path. Then cd to the directory where you've unpacked the sources and run this command for MinGW:
mingw32-make
Or this command for Cygwin:
make
Then follow the installation instructions below.
Installing LuaJIT
Copy luajit.exe and lua51.dll (built in the src directory) to a newly created directory (any location is ok). Add lua and lua\jit directories below it and copy all Lua files from the lib directory of the distribution to the latter directory.
There are no hardcoded absolute path names — all modules are loaded relative to the directory where luajit.exe is installed (see src/luaconf.h).
Cross-compiling LuaJIT
The build system has limited support for cross-compilation. For details check the comments in src/Makefile. Here are some popular examples:
You can cross-compile to a 32 bit binary on a multilib x64 OS by installing the multilib development pacakges (e.g. libc6-dev-i386 on Debian/Ubuntu) and running:
make CC="gcc -m32"
You can cross-compile for a Windows target on Debian/Ubuntu by installing the mingw32 package and running:
make CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
Embedding LuaJIT
LuaJIT is API-compatible with Lua 5.1. If you've already embedded Lua into your application, you probably don't need to do anything to switch to LuaJIT, except link with a different library. Additional hints:
- Make sure you use luaL_newstate. Avoid using lua_newstate, since this uses the (slower) default memory allocator from your system (no support for this on x64).
- Make sure you use luaL_openlibs and not the old Lua 5.0 style of calling luaopen_base etc. directly.
- To change which standard libraries to load, copy src/lib_init.c to your project and modify it accordingly. Make sure the jit library is loaded or the JIT compiler will not be activated.
- Here's a » simple example.
64 bit applications on OSX must be linked with these options (only the main executable):
-pagezero_size 10000 -image_base 100000000