1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <title>Installation
</title>
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=iso-8859-1">
6 <meta name=
"Copyright" content=
"Copyright (C) 2005-2023">
7 <meta name=
"Language" content=
"en">
8 <link rel=
"stylesheet" type=
"text/css" href=
"bluequad.css" media=
"screen">
9 <link rel=
"stylesheet" type=
"text/css" href=
"bluequad-print.css" media=
"print">
10 <style type=
"text/css">
16 border: 1px solid
#bfcfff;
19 table
.compat tr
.compathead td
{
21 border-bottom: 2px solid
#bfcfff;
36 <a href=
"https://luajit.org"><span>Lua
<span id=
"logo">JIT
</span></span></a>
43 <a href=
"luajit.html">LuaJIT
</a>
45 <a href=
"https://luajit.org/download.html">Download
<span class=
"ext">»</span></a>
47 <a class=
"current" href=
"install.html">Installation
</a>
49 <a href=
"running.html">Running
</a>
52 <a href=
"extensions.html">Extensions
</a>
54 <a href=
"ext_ffi.html">FFI Library
</a>
56 <a href=
"ext_ffi_tutorial.html">FFI Tutorial
</a>
58 <a href=
"ext_ffi_api.html">ffi.* API
</a>
60 <a href=
"ext_ffi_semantics.html">FFI Semantics
</a>
63 <a href=
"ext_jit.html">jit.* Library
</a>
65 <a href=
"ext_c_api.html">Lua/C API
</a>
68 <a href=
"https://luajit.org/status.html">Status
<span class=
"ext">»</span></a>
70 <a href=
"https://luajit.org/faq.html">FAQ
<span class=
"ext">»</span></a>
72 <a href=
"https://luajit.org/list.html">Mailing List
<span class=
"ext">»</span></a>
77 LuaJIT is only distributed as source code
— get it from the
78 <a href=
"https://luajit.org/download.html"><span class=
"ext">»</span> git repository
</a>. This page explains how to build
79 and install the LuaJIT binary and library for different operating systems.
82 For the impatient (on POSIX systems):
85 make
&& sudo make install
88 <h2 id=
"req">Requirements
</h2>
90 LuaJIT currently builds out-of-the box on most systems. Please check the
91 supported operating systems and CPU architectures on the
92 <a href=
"https://luajit.org/status.html"><span class=
"ext">»</span> status page
</a>.
95 Building LuaJIT requires a recent toolchain based on GCC, Clang/LLVM or
99 The Makefile-based build system requires GNU Make and supports
103 Batch files are provided for MSVC++ builds and console cross-builds.
106 <h2>Configuring LuaJIT
</h2>
108 The standard configuration should work fine for most installations.
109 Usually there is no need to tweak the settings. The following files
110 hold all user-configurable settings:
113 <li><tt>Makefile
</tt> has settings for
<b>installing
</b> LuaJIT (POSIX
115 <li><tt>src/Makefile
</tt> has settings for
<b>compiling
</b> LuaJIT
116 under POSIX, MinGW or Cygwin.
</li>
117 <li><tt>src/msvcbuild.bat
</tt> has settings for compiling LuaJIT with
118 MSVC (Visual Studio).
</li>
121 Please read the instructions given in these files, before changing
125 <h2 id=
"posix">POSIX Systems (Linux, macOS, *BSD etc.)
</h2>
126 <h3>Prerequisites
</h3>
128 Depending on your distribution, you may need to install a package for a
129 compiler (GCC or Clang/LLVM), the development headers and/or a complete SDK.
130 E.g. on a current Debian/Ubuntu, install
<tt>build-essential
</tt> with the
134 <h3>Building LuaJIT
</h3>
136 The supplied Makefiles try to auto-detect the settings needed for your
137 operating system and your compiler. They need to be run with GNU Make,
138 which is probably the default on your system, anyway. Simply run:
144 This always builds a native binary, depending on the host OS
145 you're running this command on. Check the section on
146 <a href=
"#cross">cross-compilation
</a> for more options.
149 By default, modules are only searched under the prefix
<tt>/usr/local
</tt>.
150 You can add an extra prefix to the search paths by appending the
151 <tt>PREFIX
</tt> option, e.g.:
154 make PREFIX=/home/myself/lj2
157 Please use the LuaJIT
2.1 branch to compile for
158 <b id=
"osx">macOS (OSX)
</b>.
160 <h3>Installing LuaJIT
</h3>
162 The top-level Makefile installs LuaJIT by default under
163 <tt>/usr/local
</tt>, i.e. the executable ends up in
164 <tt>/usr/local/bin
</tt> and so on. You need root privileges
165 to write to this path. So, assuming sudo is installed on your system,
166 run the following command and enter your sudo password:
172 Otherwise specify the directory prefix as an absolute path, e.g.:
175 make install PREFIX=/home/myself/lj2
178 Obviously the prefixes given during build and installation need to be the same.
181 <h2 id=
"windows">Windows Systems
</h2>
182 <h3>Prerequisites
</h3>
184 Either install one of the open source SDKs
185 (
<a href=
"http://mingw.org/"><span class=
"ext">»</span> MinGW
</a> or
186 <a href=
"https://www.cygwin.com/"><span class=
"ext">»</span> Cygwin
</a>), which come with a modified
187 GCC plus the required development headers.
188 Or install Microsoft's Visual Studio (MSVC).
190 <h3>Building with MSVC
</h3>
192 Open a
"Visual Studio Command Prompt" (either x86 or x64),
<tt>cd
</tt> to the
193 directory with the source code and run these commands:
200 Check the
<tt>msvcbuild.bat
</tt> file for more options.
201 Then follow the installation instructions below.
203 <h3>Building with MinGW or Cygwin
</h3>
205 Open a command prompt window and make sure the MinGW or Cygwin programs
206 are in your path. Then
<tt>cd
</tt> to the directory of the git repository.
207 Then run this command for MinGW:
213 Or this command for Cygwin:
219 Then follow the installation instructions below.
221 <h3>Installing LuaJIT
</h3>
223 Copy
<tt>luajit.exe
</tt> and
<tt>lua51.dll
</tt> (built in the
<tt>src
</tt>
224 directory) to a newly created directory (any location is ok).
225 Add
<tt>lua
</tt> and
<tt>lua\jit
</tt> directories below it and copy
226 all Lua files from the
<tt>src\jit
</tt> directory of the distribution
227 to the latter directory.
230 There are no hardcoded
231 absolute path names
— all modules are loaded relative to the
232 directory where
<tt>luajit.exe
</tt> is installed
233 (see
<tt>src/luaconf.h
</tt>).
236 <h2 id=
"cross">Cross-compiling LuaJIT
</h2>
238 The GNU Makefile-based build system allows cross-compiling on any host
239 for any supported target, as long as both architectures have the same
240 pointer size. If you want to cross-compile to any
32 bit target on an
241 x64 OS, you need to install the multilib development package (e.g.
242 <tt>libc6-dev-i386
</tt> on Debian/Ubuntu) and build a
32 bit host part
243 (
<tt>HOST_CC=
"gcc -m32"</tt>).
246 You need to specify
<tt>TARGET_SYS
</tt> whenever the host OS and the
247 target OS differ, or you'll get assembler or linker errors. E.g. if
248 you're compiling on a Windows or macOS host for embedded Linux or Android,
249 you need to add
<tt>TARGET_SYS=Linux
</tt> to the examples below. For a
250 minimal target OS, you may need to disable the built-in allocator in
251 <tt>src/Makefile
</tt> and use
<tt>TARGET_SYS=Other
</tt>. Don't forget to
252 specify the same
<tt>TARGET_SYS
</tt> for the install step, too.
255 The examples below only show some popular targets
— please check
256 the comments in
<tt>src/Makefile
</tt> for more details.
259 # Cross-compile to a
32 bit binary on a multilib x64 OS
262 # Cross-compile on Debian/Ubuntu for Windows (mingw32 package)
263 make
HOST_CC=
"gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
266 The
<tt>CROSS
</tt> prefix allows specifying a standard GNU cross-compile
267 toolchain (Binutils, GCC and a matching libc). The prefix may vary
268 depending on the
<tt>--target
</tt> the toolchain was built for (note the
269 <tt>CROSS
</tt> prefix has a trailing
<tt>"-"</tt>). The examples below
270 use the canonical toolchain triplets for Linux.
273 Since there's often no easy way to detect CPU features at runtime, it's
274 important to compile with the proper CPU or architecture settings. You
275 can specify these when building the toolchain yourself. Or add
276 <tt>-mcpu=...
</tt> or
<tt>-march=...
</tt> to
<tt>TARGET_CFLAGS
</tt>. For
277 ARM it's important to have the correct
<tt>-mfloat-abi=...
</tt> setting,
278 too. Otherwise, LuaJIT may not run at the full performance of your target
283 make
HOST_CC=
"gcc -m32" CROSS=arm-linux-gnueabi- \
284 TARGET_CFLAGS=
"-mfloat-abi=soft"
286 # ARM soft-float ABI with VFP (example for Cortex-A8)
287 make
HOST_CC=
"gcc -m32" CROSS=arm-linux-gnueabi- \
288 TARGET_CFLAGS=
"-mcpu=cortex-a8 -mfloat-abi=softfp"
290 # ARM hard-float ABI with VFP (armhf, requires recent toolchain)
291 make
HOST_CC=
"gcc -m32" CROSS=arm-linux-gnueabihf-
294 make
HOST_CC=
"gcc -m32" CROSS=powerpc-linux-gnu-
295 # PPC/e500v2 (fast interpreter only)
296 make
HOST_CC=
"gcc -m32" CROSS=powerpc-e500v2-linux-gnuspe-
299 make
HOST_CC=
"gcc -m32" CROSS=mips-linux-
301 make
HOST_CC=
"gcc -m32" CROSS=mipsel-linux-
304 You can cross-compile for
<b id=
"android">Android
</b> using the
<a href=
"https://developer.android.com/ndk/"><span class=
"ext">»</span> Android NDK
</a>.
305 Please adapt the environment variables to match the install locations and the
306 desired target platform. E.g. Android
4.1 corresponds to ABI level
16.
309 # Android/ARM, armeabi-v7a (ARMv7 VFP), Android
4.1+ (JB)
311 NDKDIR=/opt/android/ndk
312 NDKBIN=$NDKDIR/toolchains/llvm/prebuilt/linux-x86_64/bin
313 NDKCROSS=$NDKBIN/arm-linux-androideabi-
314 NDKCC=$NDKBIN/armv7a-linux-androideabi16-clang
315 make
HOST_CC=
"gcc -m32" CROSS=$NDKCROSS \
316 STATIC_CC=$NDKCC
DYNAMIC_CC=
"$NDKCC -fPIC" \
317 TARGET_LD=$NDKCC
TARGET_AR=
"$NDKBIN/llvm-ar rcus" \
318 TARGET_STRIP=$NDKBIN/llvm-strip
321 Please use the LuaJIT
2.1 branch to compile for
322 <b id=
"ios">iOS
</b> (iPhone/iPad).
325 <h3 id=
"consoles">Cross-compiling for consoles
</h3>
327 Building LuaJIT for consoles requires both a supported host compiler
328 (x86 or x64) and a cross-compiler from the official console SDK.
331 Due to restrictions on consoles, the JIT compiler is disabled and only
332 the fast interpreter is built. This is still faster than plain Lua,
333 but much slower than the JIT compiler. The FFI is disabled, too, since
334 it's not very useful in such an environment.
337 The following commands build a static library
<tt>libluajit.a
</tt>,
338 which can be linked against your game, just like the Lua library.
341 To cross-compile for
<b id=
"ps3">PS3
</b> from a Linux host (requires
342 32 bit GCC, i.e. multilib Linux/x64) or a Windows host (requires
343 32 bit MinGW), run this command:
346 make
HOST_CC=
"gcc -m32" CROSS=ppu-lv2-
349 To cross-compile for the other consoles from a Windows host, open a
350 "Native Tools Command Prompt for VS". You need to choose either the
32
351 or the
64 bit version of the host compiler to match the target.
352 Then
<tt>cd
</tt> to the
<tt>src
</tt> directory below the source code
353 and run the build command given in the table:
355 <table class=
"compat">
356 <tr class=
"compathead">
357 <td class=
"compatname">Console
</td>
358 <td class=
"compatbits">Bits
</td>
359 <td class=
"compatx">Build Command
</td>
361 <tr class=
"odd separate">
362 <td class=
"compatname"><b id=
"ps4">PS4
</b></td>
363 <td class=
"compatbits">64</td>
364 <td class=
"compatx"><tt>ps4build
</tt></td>
367 <td class=
"compatname"><b id=
"psvita">PS Vita
</b></td>
368 <td class=
"compatbits">32</td>
369 <td class=
"compatx"><tt>psvitabuild
</tt></td>
372 <td class=
"compatname"><b id=
"xbox360">Xbox
360</b></td>
373 <td class=
"compatbits">32</td>
374 <td class=
"compatx"><tt>xedkbuild
</tt></td>
378 Please check out the comments in the corresponding
<tt>*.bat
</tt>
379 file for more options.
382 <h2 id=
"embed">Embedding LuaJIT
</h2>
384 LuaJIT is API-compatible with Lua
5.1. If you've already embedded Lua
385 into your application, you probably don't need to do anything to switch
386 to LuaJIT, except link with a different library:
389 <li>It's strongly suggested to build LuaJIT separately using the supplied
390 build system. Please do
<em>not
</em> attempt to integrate the individual
391 source files into your build tree. You'll most likely get the internal build
392 dependencies wrong or mess up the compiler flags. Treat LuaJIT like any
393 other external library and link your application with either the dynamic
394 or static library, depending on your needs.
</li>
395 <li>If you want to load C modules compiled for plain Lua
396 with
<tt>require()
</tt>, you need to make sure the public symbols
397 (e.g.
<tt>lua_pushnumber
</tt>) are exported, too:
398 <ul><li>On POSIX systems you can either link to the shared library
399 or link the static library into your application. In the latter case
400 you'll need to export all public symbols from your main executable
401 (e.g.
<tt>-Wl,-E
</tt> on Linux) and add the external dependencies
402 (e.g.
<tt>-lm -ldl
</tt> on Linux).
</li>
403 <li>Since Windows symbols are bound to a specific DLL name, you need to
404 link to the
<tt>lua51.dll
</tt> created by the LuaJIT build (do not rename
405 the DLL). You may link LuaJIT statically on Windows only if you don't
406 intend to load Lua/C modules at runtime.
410 <p>Additional hints for initializing LuaJIT using the C API functions:
</p>
413 <a href=
"http://lua-users.org/wiki/SimpleLuaApiExample"><span class=
"ext">»</span> simple example
</a>
414 for embedding Lua or LuaJIT into your application.
</li>
415 <li>Make sure you use
<tt>luaL_newstate
</tt>. Avoid using
416 <tt>lua_newstate
</tt>, since this uses the (slower) default memory
417 allocator from your system (no support for this on
64 bit architectures).
</li>
418 <li>Make sure you use
<tt>luaL_openlibs
</tt> and not the old Lua
5.0 style
419 of calling
<tt>luaopen_base
</tt> etc. directly.
</li>
420 <li>To change or extend the list of standard libraries to load, copy
421 <tt>src/lib_init.c
</tt> to your project and modify it accordingly.
422 Make sure the
<tt>jit
</tt> library is loaded, or the JIT compiler
423 will not be activated.
</li>
424 <li>The
<tt>bit.*
</tt> module for bitwise operations
425 is already built-in. There's no need to statically link
426 <a href=
"https://bitop.luajit.org/"><span class=
"ext">»</span> Lua BitOp
</a> to your application.
</li>
429 <h2 id=
"distro">Hints for Distribution Maintainers
</h2>
431 The LuaJIT build system has extra provisions for the needs of most
432 POSIX-based distributions. If you're a package maintainer for
433 a distribution,
<em>please
</em> make use of these features and
434 avoid patching, subverting, autotoolizing or messing up the build system
438 There should be absolutely no need to patch
<tt>luaconf.h
</tt> or any
439 of the Makefiles. And please do not hand-pick files for your packages
—
440 simply use whatever
<tt>make install
</tt> creates. There's a reason
441 for all the files
<em>and
</em> directories it creates.
444 The build system uses GNU make and auto-detects most settings based on
445 the host you're building it on. This should work fine for native builds,
446 even when sandboxed. You may need to pass some of the following flags to
447 <em>both
</em> the
<tt>make
</tt> and the
<tt>make install
</tt> command lines
448 for a regular distribution build:
451 <li><tt>PREFIX
</tt> overrides the installation path and should usually
452 be set to
<tt>/usr
</tt>. Setting this also changes the module paths and
453 the paths needed to locate the shared library.
</li>
454 <li><tt>DESTDIR
</tt> is an absolute path which allows you to install
455 to a shadow tree instead of the root tree of the build system.
</li>
456 <li><tt>MULTILIB
</tt> sets the architecture-specific library path component
457 for multilib systems. The default is
<tt>lib
</tt>.
</li>
458 <li>Have a look at the top-level
<tt>Makefile
</tt> and
<tt>src/Makefile
</tt>
459 for additional variables to tweak. The following variables
<em>may
</em> be
460 overridden, but it's
<em>not
</em> recommended, except for special needs
462 <tt>BUILDMODE, CC, HOST_CC, STATIC_CC, DYNAMIC_CC, CFLAGS, HOST_CFLAGS,
463 TARGET_CFLAGS, LDFLAGS, HOST_LDFLAGS, TARGET_LDFLAGS, TARGET_SHLDFLAGS,
464 TARGET_FLAGS, LIBS, HOST_LIBS, TARGET_LIBS, CROSS, HOST_SYS, TARGET_SYS
468 The build system has a special target for an amalgamated build, i.e.
469 <tt>make amalg
</tt>. This compiles the LuaJIT core as one huge C file
470 and allows GCC to generate faster and shorter code. Alas, this requires
471 lots of memory during the build. This may be a problem for some users,
472 that's why it's not enabled by default. But it shouldn't be a problem for
473 most build farms. It's recommended that binary distributions use this
474 target for their LuaJIT builds.
477 The tl;dr version of the above:
480 make amalg PREFIX=/usr && \
481 make install PREFIX=/usr DESTDIR=/tmp/buildroot
484 Finally, if you encounter any difficulties, please
485 <a href=
"contact.html">contact me
</a> first, instead of releasing a broken
486 package onto unsuspecting users. Because they'll usually gonna complain
487 to me (the upstream) and not you (the package maintainer), anyway.
493 Copyright
© 2005-
2023
494 <span class=
"noprint">
496 <a href=
"contact.html">Contact
</a>