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=
"Author" content=
"Mike Pall">
7 <meta name=
"Copyright" content=
"Copyright (C) 2005-2012, Mike Pall">
8 <meta name=
"Language" content=
"en">
9 <link rel=
"stylesheet" type=
"text/css" href=
"bluequad.css" media=
"screen">
10 <link rel=
"stylesheet" type=
"text/css" href=
"bluequad-print.css" media=
"print">
11 <style type=
"text/css">
17 border: 1px solid
#bfcfff;
21 table
.compat tr
.compathead td
{
23 border-bottom: 2px solid
#bfcfff;
25 tr
.compathead td
.compatos
{
28 table
.compat td
.compatcpu
{
30 border-right: 2px solid
#bfcfff;
34 vertical-align: middle
;
37 background-color: #d0d0d0;
43 <a href=
"http://luajit.org"><span>Lua
<span id=
"logo">JIT
</span></span></a>
50 <a href=
"luajit.html">LuaJIT
</a>
52 <a class=
"current" href=
"install.html">Installation
</a>
54 <a href=
"running.html">Running
</a>
57 <a href=
"extensions.html">Extensions
</a>
59 <a href=
"ext_ffi.html">FFI Library
</a>
61 <a href=
"ext_ffi_tutorial.html">FFI Tutorial
</a>
63 <a href=
"ext_ffi_api.html">ffi.* API
</a>
65 <a href=
"ext_ffi_semantics.html">FFI Semantics
</a>
68 <a href=
"ext_jit.html">jit.* Library
</a>
70 <a href=
"ext_c_api.html">Lua/C API
</a>
73 <a href=
"status.html">Status
</a>
75 <a href=
"changes.html">Changes
</a>
78 <a href=
"faq.html">FAQ
</a>
80 <a href=
"http://luajit.org/performance.html">Performance
<span class=
"ext">»</span></a>
82 <a href=
"http://luajit.org/download.html">Download
<span class=
"ext">»</span></a>
87 LuaJIT is only distributed as a source package. This page explains
88 how to build and install LuaJIT with different operating systems
92 For the impatient (on POSIX systems):
95 make
&& sudo make install
98 LuaJIT currently builds out-of-the box on most systems.
99 Here's the compatibility matrix for the supported combinations of
100 operating systems, CPUs and compilers:
102 <table class=
"compat">
103 <tr class=
"compathead">
104 <td class=
"compatcpu">CPU / OS
</td>
105 <td class=
"compatos"><a href=
"#posix">Linux
</a> or
<br><a href=
"#android">Android
</a></td>
106 <td class=
"compatos"><a href=
"#posix">*BSD, Other
</a></td>
107 <td class=
"compatos"><a href=
"#posix">OSX
10.4+
</a> or
<br><a href=
"#ios">iOS
3.0+
</a></td>
108 <td class=
"compatos"><a href=
"#windows">Windows
<br>XP/Vista/
7</a></td>
110 <tr class=
"odd separate">
111 <td class=
"compatcpu">x86 (
32 bit)
</td>
112 <td class=
"compatos">GCC
4.x
<br>GCC
3.4</td>
113 <td class=
"compatos">GCC
4.x
<br>GCC
3.4</td>
114 <td class=
"compatos">GCC
4.x
<br>GCC
3.4</td>
115 <td class=
"compatos">MSVC, MSVC/EE
<br>WinSDK
<br>MinGW, Cygwin
</td>
118 <td class=
"compatcpu">x64 (
64 bit)
</td>
119 <td class=
"compatos">GCC
4.x
</td>
120 <td class=
"compatos compatno"> </td>
121 <td class=
"compatos">GCC
4.x
</td>
122 <td class=
"compatos">MSVC + SDK v7.0
<br>WinSDK v7.0
</td>
125 <td class=
"compatcpu"><a href=
"#android">ARMv5+
<br>ARM9E+
</a></td>
126 <td class=
"compatos">GCC
4.2+
</td>
127 <td class=
"compatos">GCC
4.2+
</td>
128 <td class=
"compatos">GCC
4.2+
</td>
129 <td class=
"compatos compatno"> </td>
132 <td class=
"compatcpu"><a href=
"#ppc">PPC
</a></td>
133 <td class=
"compatos">GCC
4.3+
</td>
134 <td class=
"compatos">GCC
4.3+
</td>
135 <td class=
"compatos compatno"> </td>
136 <td class=
"compatos compatno"> </td>
139 <td class=
"compatcpu"><a href=
"#ppc">PPC/e500v2
</a></td>
140 <td class=
"compatos">GCC
4.3+
</td>
141 <td class=
"compatos">GCC
4.3+
</td>
142 <td class=
"compatos compatno"> </td>
143 <td class=
"compatos compatno"> </td>
146 <td class=
"compatcpu"><a href=
"#mips">MIPS
</a></td>
147 <td class=
"compatos">GCC
4.3+
</td>
148 <td class=
"compatos">GCC
4.3+
</td>
149 <td class=
"compatos compatno"> </td>
150 <td class=
"compatos compatno"> </td>
154 <h2>Configuring LuaJIT
</h2>
156 The standard configuration should work fine for most installations.
157 Usually there is no need to tweak the settings. The following files
158 hold all user-configurable settings:
161 <li><tt>src/luaconf.h
</tt> sets some configuration variables.
</li>
162 <li><tt>Makefile
</tt> has settings for
<b>installing
</b> LuaJIT (POSIX
164 <li><tt>src/Makefile
</tt> has settings for
<b>compiling
</b> LuaJIT
165 under POSIX, MinGW or Cygwin.
</li>
166 <li><tt>src/msvcbuild.bat
</tt> has settings for compiling LuaJIT with
170 Please read the instructions given in these files, before changing
174 <h2 id=
"posix">POSIX Systems (Linux, OSX, *BSD etc.)
</h2>
175 <h3>Prerequisites
</h3>
177 Depending on your distribution, you may need to install a package for
178 GCC, the development headers and/or a complete SDK. E.g. on a current
179 Debian/Ubuntu, install
<tt>libc6-dev
</tt> with the package manager.
182 Download the current source package of LuaJIT (pick the .tar.gz),
183 if you haven't already done so. Move it to a directory of your choice,
184 open a terminal window and change to this directory. Now unpack the archive
185 and change to the newly created directory:
188 tar zxf LuaJIT-
2.0.0-beta9.tar.gz
189 cd LuaJIT-
2.0.0-beta9
</pre>
190 <h3>Building LuaJIT
</h3>
192 The supplied Makefiles try to auto-detect the settings needed for your
193 operating system and your compiler. They need to be run with GNU Make,
194 which is probably the default on your system, anyway. Simply run:
200 This always builds a native x86, x64 or PPC binary, depending on the host OS
201 you're running this command on. Check the section on
202 <a href=
"#cross">cross-compilation
</a> for more options.
205 By default, modules are only searched under the prefix
<tt>/usr/local
</tt>.
206 You can add an extra prefix to the search paths by appending the
207 <tt>PREFIX
</tt> option, e.g.:
210 make PREFIX=/home/myself/lj2
213 Note for OSX: if the
<tt>MACOSX_DEPLOYMENT_TARGET
</tt> environment
214 variable is not set, then it's forced to
<tt>10.4</tt>.
216 <h3>Installing LuaJIT
</h3>
218 The top-level Makefile installs LuaJIT by default under
219 <tt>/usr/local
</tt>, i.e. the executable ends up in
220 <tt>/usr/local/bin
</tt> and so on. You need root privileges
221 to write to this path. So, assuming sudo is installed on your system,
222 run the following command and enter your sudo password:
228 Otherwise specify the directory prefix as an absolute path, e.g.:
231 make install PREFIX=/home/myself/lj2
234 Obviously the prefixes given during build and installation need to be the same.
236 <p style=
"color: #c00000;">
237 Note: to avoid overwriting a previous version, the beta test releases
238 only install the LuaJIT executable under the versioned name (i.e.
239 <tt>luajit-
2.0.0-beta9
</tt>). You probably want to create a symlink
240 for convenience, with a command like this:
242 <pre class=
"code" style=
"color: #c00000;">
243 sudo ln -sf luajit-
2.0.0-beta9
/usr/local/bin/luajit
246 <h2 id=
"windows">Windows Systems
</h2>
247 <h3>Prerequisites
</h3>
249 Either install one of the open source SDKs
250 (
<a href=
"http://mingw.org/"><span class=
"ext">»</span> MinGW
</a> or
251 <a href=
"http://www.cygwin.com/"><span class=
"ext">»</span> Cygwin
</a>), which come with a modified
252 GCC plus the required development headers.
255 Or install Microsoft's Visual C++ (MSVC). The freely downloadable
256 <a href=
"http://www.microsoft.com/Express/VC/"><span class=
"ext">»</span> Express Edition
</a>
257 works just fine, but only contains an x86 compiler.
260 The freely downloadable
261 <a href=
"http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx"><span class=
"ext">»</span> Windows SDK
</a>
262 only comes with command line tools, but this is all you need to build LuaJIT.
263 It contains x86 and x64 compilers.
266 Next, download the source package and unpack it using an archive manager
267 (e.g. the Windows Explorer) to a directory of your choice.
269 <h3>Building with MSVC
</h3>
271 Open a
"Visual Studio .NET Command Prompt",
<tt>cd
</tt> to the
272 directory where you've unpacked the sources and run these commands:
279 Then follow the installation instructions below.
281 <h3>Building with the Windows SDK
</h3>
283 Open a
"Windows SDK Command Shell" and select the x86 compiler:
289 Or select the x64 compiler:
295 Then
<tt>cd
</tt> to the directory where you've unpacked the sources
296 and run these commands:
303 Then follow the installation instructions below.
305 <h3>Building with MinGW or Cygwin
</h3>
307 Open a command prompt window and make sure the MinGW or Cygwin programs
308 are in your path. Then
<tt>cd
</tt> to the directory where
309 you've unpacked the sources and run this command for MinGW:
315 Or this command for Cygwin:
321 Then follow the installation instructions below.
323 <h3>Installing LuaJIT
</h3>
325 Copy
<tt>luajit.exe
</tt> and
<tt>lua51.dll
</tt> (built in the
<tt>src
</tt>
326 directory) to a newly created directory (any location is ok).
327 Add
<tt>lua
</tt> and
<tt>lua\jit
</tt> directories below it and copy
328 all Lua files from the
<tt>lib
</tt> directory of the distribution
329 to the latter directory.
332 There are no hardcoded
333 absolute path names
— all modules are loaded relative to the
334 directory where
<tt>luajit.exe
</tt> is installed
335 (see
<tt>src/luaconf.h
</tt>).
338 <h2 id=
"cross">Cross-compiling LuaJIT
</h2>
340 The build system has limited support for cross-compilation. For details
341 check the comments in
<tt>src/Makefile
</tt>. Here are some popular examples:
344 You can cross-compile to a
<b>32 bit binary on a multilib x64 OS
</b> by
345 installing the multilib development packages (e.g.
<tt>libc6-dev-i386
</tt>
346 on Debian/Ubuntu) and running:
352 You can cross-compile for a
<b>Windows target on Debian/Ubuntu
</b> by
353 installing the
<tt>mingw32
</tt> package and running:
356 make
HOST_CC=
"gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
359 You can cross-compile for an
<b>ARM target
</b> on an x86 or x64 host
360 system using a standard GNU cross-compile toolchain (Binutils, GCC,
361 EGLIBC). The
<tt>CROSS
</tt> prefix may vary depending on the
362 <tt>--target
</tt> of the toolchain:
365 make
HOST_CC=
"gcc -m32" CROSS=arm-linux-gnueabi-
368 You can cross-compile for
<b id=
"android">Android (ARM)
</b> using the
<a href=
"http://developer.android.com/sdk/ndk/index.html"><span class=
"ext">»</span> Android NDK
</a>.
369 The environment variables need to match the install locations and the
370 desired target platform. E.g. Android
2.2 corresponds to ABI level
8:
375 NDKVER=$NDK/toolchains/arm-linux-androideabi-
4.4.3
376 NDKP=$NDKVER/prebuilt/linux-x86/bin/arm-linux-androideabi-
377 NDKF=
"--sysroot $NDK/platforms/android-$NDKABI/arch-arm"
378 make
HOST_CC=
"gcc -m32" CROSS=$NDKP
TARGET_FLAGS=
"$NDKF"
381 You can cross-compile for
<b id=
"ios">iOS
3.0+
</b> (iPhone/iPad) using the
<a href=
"http://developer.apple.com/devcenter/ios/index.action"><span class=
"ext">»</span> iOS SDK
</a>.
382 The environment variables need to match the iOS SDK version:
384 <p style=
"font-size: 8pt;">
385 Note:
<b>the JIT compiler is disabled for iOS
</b>, because regular iOS Apps
386 are not allowed to generate code at runtime. You'll only get the performance
387 of the LuaJIT interpreter on iOS. This is still faster than plain Lua, but
388 much slower than the JIT compiler. Please complain to Apple, not me.
392 ISDK=/Developer/Platforms/iPhoneOS.platform/Developer
393 ISDKVER=iPhoneOS4.3.sdk
395 ISDKF=
"-arch armv6 -isysroot $ISDK/SDKs/$ISDKVER"
396 make
HOST_CC=
"gcc -m32 -arch i386" CROSS=$ISDKP
TARGET_FLAGS=
"$ISDKF" \
400 You can cross-compile for a
<b id=
"ppc">PPC target
</b> or a
401 <b>PPC/e500v2 target
</b> on x86 or x64 host systems using a standard
402 GNU cross-compile toolchain (Binutils, GCC, EGLIBC).
403 The
<tt>CROSS
</tt> prefix may vary depending on the
<tt>--target
</tt>
408 make
HOST_CC=
"gcc -m32" CROSS=powerpc-linux-gnu-
412 make
HOST_CC=
"gcc -m32" CROSS=powerpc-e500v2-linux-gnuspe-
415 You can cross-compile for a big-endian or little-endian
416 <b id=
"mips">MIPS target
</b> on x86 or x64 host systems using a standard
417 GNU cross-compile toolchain (Binutils, GCC, EGLIBC).
418 The
<tt>CROSS
</tt> prefix may vary depending on the
<tt>--target
</tt>
423 make
HOST_CC=
"gcc -m32" CROSS=mips-linux-
427 make
HOST_CC=
"gcc -m32" CROSS=mipsel-linux-
430 Whenever the
<b>host OS and the target OS differ
</b>, you need to specify
431 <tt>TARGET_SYS
</tt> or you'll get assembler or linker errors. E.g. if
432 you're compiling on a Windows or OSX host for embedded Linux or Android,
433 you need to add
<tt>TARGET_SYS=Linux
</tt> to the examples above. For a
434 minimal target OS, you may need to disable the built-in allocator in
435 <tt>src/Makefile
</tt> and use
<tt>TARGET_SYS=Other
</tt>.
438 <h2 id=
"embed">Embedding LuaJIT
</h2>
440 LuaJIT is API-compatible with Lua
5.1. If you've already embedded Lua
441 into your application, you probably don't need to do anything to switch
442 to LuaJIT, except link with a different library:
445 <li>It's strongly suggested to build LuaJIT separately using the supplied
446 build system. Please do
<em>not
</em> attempt to integrate the individual
447 source files into your build tree. You'll most likely get the internal build
448 dependencies wrong or mess up the compiler flags. Treat LuaJIT like any
449 other external library and link your application with either the dynamic
450 or static library, depending on your needs.
</li>
451 <li>If you want to load C modules compiled for plain Lua
452 with
<tt>require()
</tt>, you need to make sure the public symbols
453 (e.g.
<tt>lua_pushnumber
</tt>) are exported, too:
454 <ul><li>On POSIX systems you can either link to the shared library
455 or link the static library into your application. In the latter case
456 you'll need to export all public symbols from your main executable
457 (e.g.
<tt>-Wl,-E
</tt> on Linux) and add the external dependencies
458 (e.g.
<tt>-lm -ldl
</tt> on Linux).
</li>
459 <li>Since Windows symbols are bound to a specific DLL name, you need to
460 link to the
<tt>lua51.dll
</tt> created by the LuaJIT build (do not rename
461 the DLL). You may link LuaJIT statically on Windows only if you don't
462 intend to load Lua/C modules at runtime.
466 If you're building a
64 bit application on OSX which links directly or
467 indirectly against LuaJIT, you need to link your main executable
470 -pagezero_size
10000 -image_base
100000000
472 Also, it's recommended to
<tt>rebase
</tt> all (self-compiled) shared libraries
473 which are loaded at runtime on OSX/x64 (e.g. C extension modules for Lua).
474 See:
<tt>man rebase
</tt>
477 <p>Additional hints for initializing LuaJIT using the C API functions:
</p>
480 <a href=
"http://lua-users.org/wiki/SimpleLuaApiExample"><span class=
"ext">»</span> simple example
</a>
481 for embedding Lua or LuaJIT into your application.
</li>
482 <li>Make sure you use
<tt>luaL_newstate
</tt>. Avoid using
483 <tt>lua_newstate
</tt>, since this uses the (slower) default memory
484 allocator from your system (no support for this on x64).
</li>
485 <li>Make sure you use
<tt>luaL_openlibs
</tt> and not the old Lua
5.0 style
486 of calling
<tt>luaopen_base
</tt> etc. directly.
</li>
487 <li>To change or extend the list of standard libraries to load, copy
488 <tt>src/lib_init.c
</tt> to your project and modify it accordingly.
489 Make sure the
<tt>jit
</tt> library is loaded or the JIT compiler
490 will not be activated.
</li>
491 <li>The
<tt>bit.*
</tt> module for bitwise operations
492 is already built-in. There's no need to statically link
493 <a href=
"http://bitop.luajit.org/"><span class=
"ext">»</span> Lua BitOp
</a> to your application.
</li>
496 <h2 id=
"distro">Hints for Distribution Maintainers
</h2>
498 The LuaJIT build system has extra provisions for the needs of most
499 POSIX-based distributions. If you're a package maintainer for
500 a distribution,
<em>please
</em> make use of these features and
501 avoid patching, subverting, autotoolizing or messing up the build system
505 There should be absolutely no need to patch
<tt>luaconf.h
</tt> or any
506 of the Makefiles. And please do not hand-pick files for your packages
—
507 simply use whatever
<tt>make install
</tt> creates. There's a reason
508 for all of the files
<em>and
</em> directories it creates.
511 The build system uses GNU make and auto-detects most settings based on
512 the host you're building it on. This should work fine for native builds,
513 even when sandboxed. You may need to pass some of the following flags to
514 <em>both
</em> the
<tt>make
</tt> and the
<tt>make install
</tt> command lines
515 for a regular distribution build:
518 <li><tt>PREFIX
</tt> overrides the installation path and should usually
519 be set to
<tt>/usr
</tt>. Setting this also changes the module paths and
520 the
<tt>-rpath
</tt> of the shared library.
</li>
521 <li><tt>DESTDIR
</tt> is an absolute path which allows you to install
522 to a shadow tree instead of the root tree of the build system.
</li>
523 <li>Have a look at the top-level
<tt>Makefile
</tt> and
<tt>src/Makefile
</tt>
524 for additional variables to tweak. The following variables
<em>may
</em> be
525 overridden, but it's
<em>not
</em> recommended, except for special needs
527 <tt>BUILDMODE, CC, HOST_CC, STATIC_CC, DYNAMIC_CC, CFLAGS, HOST_CFLAGS,
528 TARGET_CFLAGS, LDFLAGS, HOST_LDFLAGS, TARGET_LDFLAGS, TARGET_SHLDFLAGS,
529 TARGET_FLAGS, LIBS, HOST_LIBS, TARGET_LIBS, CROSS, HOST_SYS, TARGET_SYS
533 The build system has a special target for an amalgamated build, i.e.
534 <tt>make amalg
</tt>. This compiles the LuaJIT core as one huge C file
535 and allows GCC to generate faster and shorter code. Alas, this requires
536 lots of memory during the build. This may be a problem for some users,
537 that's why it's not enabled by default. But it shouldn't be a problem for
538 most build farms. It's recommended that binary distributions use this
539 target for their LuaJIT builds.
542 The tl;dr version of the above:
545 make amalg PREFIX=/usr && \
546 make install PREFIX=/usr DESTDIR=/tmp/buildroot
549 Finally, if you encounter any difficulties, please
550 <a href=
"contact.html">contact me
</a> first, instead of releasing a broken
551 package onto unsuspecting users. Because they'll usually gonna complain
552 to me (the upstream) and not you (the package maintainer), anyway.
558 Copyright
© 2005-
2012 Mike Pall
559 <span class=
"noprint">
561 <a href=
"contact.html">Contact
</a>