| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>Installation</title> |
| 5 | <meta charset="utf-8"> |
| 6 | <meta name="Copyright" content="Copyright (C) 2005-2025"> |
| 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"> |
| 11 | table.compat { |
| 12 | line-height: 1.2; |
| 13 | font-size: 80%; |
| 14 | } |
| 15 | table.compat td { |
| 16 | border: 1px solid #bfcfff; |
| 17 | height: 1.5em; |
| 18 | } |
| 19 | table.compat tr.compathead td { |
| 20 | font-weight: bold; |
| 21 | border-bottom: 2px solid #bfcfff; |
| 22 | } |
| 23 | td.compatname { |
| 24 | width: 10%; |
| 25 | } |
| 26 | td.compatbits { |
| 27 | width: 5%; |
| 28 | } |
| 29 | td.compatx { |
| 30 | width: 21%; |
| 31 | } |
| 32 | </style> |
| 33 | </head> |
| 34 | <body> |
| 35 | <div id="site"> |
| 36 | <a href="https://luajit.org"><span>Lua<span id="logo">JIT</span></span></a> |
| 37 | </div> |
| 38 | <div id="head"> |
| 39 | <h1>Installation</h1> |
| 40 | </div> |
| 41 | <div id="nav"> |
| 42 | <ul><li> |
| 43 | <a href="luajit.html">LuaJIT</a> |
| 44 | <ul><li> |
| 45 | <a href="https://luajit.org/download.html">Download <span class="ext">»</span></a> |
| 46 | </li><li> |
| 47 | <a class="current" href="install.html">Installation</a> |
| 48 | </li><li> |
| 49 | <a href="running.html">Running</a> |
| 50 | </li></ul> |
| 51 | </li><li> |
| 52 | <a href="extensions.html">Extensions</a> |
| 53 | <ul><li> |
| 54 | <a href="ext_ffi.html">FFI Library</a> |
| 55 | <ul><li> |
| 56 | <a href="ext_ffi_tutorial.html">FFI Tutorial</a> |
| 57 | </li><li> |
| 58 | <a href="ext_ffi_api.html">ffi.* API</a> |
| 59 | </li><li> |
| 60 | <a href="ext_ffi_semantics.html">FFI Semantics</a> |
| 61 | </li></ul> |
| 62 | </li><li> |
| 63 | <a href="ext_buffer.html">String Buffers</a> |
| 64 | </li><li> |
| 65 | <a href="ext_jit.html">jit.* Library</a> |
| 66 | </li><li> |
| 67 | <a href="ext_c_api.html">Lua/C API</a> |
| 68 | </li><li> |
| 69 | <a href="ext_profiler.html">Profiler</a> |
| 70 | </li></ul> |
| 71 | </li><li> |
| 72 | <a href="https://luajit.org/status.html">Status <span class="ext">»</span></a> |
| 73 | </li><li> |
| 74 | <a href="https://luajit.org/faq.html">FAQ <span class="ext">»</span></a> |
| 75 | </li><li> |
| 76 | <a href="https://luajit.org/list.html">Mailing List <span class="ext">»</span></a> |
| 77 | </li></ul> |
| 78 | </div> |
| 79 | <div id="main"> |
| 80 | <p> |
| 81 | LuaJIT is only distributed as source code — get it from the |
| 82 | <a href="https://luajit.org/download.html"><span class="ext">»</span> git repository</a>. This page explains how to build |
| 83 | and install the LuaJIT binary and library for different operating systems. |
| 84 | </p> |
| 85 | <p> |
| 86 | For the impatient (on POSIX systems): |
| 87 | </p> |
| 88 | <pre class="code"> |
| 89 | make && sudo make install |
| 90 | </pre> |
| 91 | |
| 92 | <h2 id="req">Requirements</h2> |
| 93 | <p> |
| 94 | LuaJIT currently builds out-of-the box on most systems. Please check the |
| 95 | supported operating systems and CPU architectures on the |
| 96 | <a href="https://luajit.org/status.html"><span class="ext">»</span> status page</a>. |
| 97 | </p> |
| 98 | <p> |
| 99 | Building LuaJIT requires a recent toolchain based on GCC, Clang/LLVM or |
| 100 | MSVC++. |
| 101 | </p> |
| 102 | <p> |
| 103 | The Makefile-based build system requires GNU Make and supports |
| 104 | cross-builds. |
| 105 | </p> |
| 106 | <p> |
| 107 | Batch files are provided for MSVC++ builds and console cross-builds. |
| 108 | </p> |
| 109 | |
| 110 | <h2>Configuring LuaJIT</h2> |
| 111 | <p> |
| 112 | The standard configuration should work fine for most installations. |
| 113 | Usually there is no need to tweak the settings. The following files |
| 114 | hold all user-configurable settings: |
| 115 | </p> |
| 116 | <ul> |
| 117 | <li><tt>Makefile</tt> has settings for <b>installing</b> LuaJIT (POSIX |
| 118 | only).</li> |
| 119 | <li><tt>src/Makefile</tt> has settings for <b>compiling</b> LuaJIT |
| 120 | under POSIX, MinGW or Cygwin.</li> |
| 121 | <li><tt>src/msvcbuild.bat</tt> has settings for compiling LuaJIT with |
| 122 | MSVC (Visual Studio).</li> |
| 123 | </ul> |
| 124 | <p> |
| 125 | Please read the instructions given in these files, before changing |
| 126 | any settings. |
| 127 | </p> |
| 128 | <p> |
| 129 | All LuaJIT 64 bit ports use 64 bit GC objects by default (<tt>LJ_GC64</tt>). |
| 130 | For x64, you can select the old 32-on-64 bit mode by adding |
| 131 | <tt>XCFLAGS=-DLUAJIT_DISABLE_GC64</tt> to the make command. |
| 132 | Please check the note about the |
| 133 | <a href="extensions.html#string_dump">bytecode format</a> differences, too. |
| 134 | </p> |
| 135 | |
| 136 | <h2 id="posix">POSIX Systems (Linux, macOS, *BSD etc.)</h2> |
| 137 | <h3>Prerequisites</h3> |
| 138 | <p> |
| 139 | Depending on your distribution, you may need to install a package for a |
| 140 | compiler (GCC or Clang/LLVM), the development headers and/or a complete SDK. |
| 141 | E.g. on a current Debian/Ubuntu, install <tt>build-essential</tt> with the |
| 142 | package manager. |
| 143 | </p> |
| 144 | </pre> |
| 145 | <h3>Building LuaJIT</h3> |
| 146 | <p> |
| 147 | The supplied Makefiles try to auto-detect the settings needed for your |
| 148 | operating system and your compiler. They need to be run with GNU Make, |
| 149 | which is probably the default on your system, anyway. Simply run: |
| 150 | </p> |
| 151 | <pre class="code"> |
| 152 | make |
| 153 | </pre> |
| 154 | <p> |
| 155 | This always builds a native binary, depending on the host OS |
| 156 | you're running this command on. Check the section on |
| 157 | <a href="#cross">cross-compilation</a> for more options. |
| 158 | </p> |
| 159 | <p> |
| 160 | By default, modules are only searched under the prefix <tt>/usr/local</tt>. |
| 161 | You can add an extra prefix to the search paths by appending the |
| 162 | <tt>PREFIX</tt> option, e.g.: |
| 163 | </p> |
| 164 | <pre class="code"> |
| 165 | make PREFIX=/home/myself/lj2 |
| 166 | </pre> |
| 167 | <p> |
| 168 | Note for macOS: you <b>must</b> set the <tt>MACOSX_DEPLOYMENT_TARGET</tt> |
| 169 | environment variable to a value supported by your toolchain: |
| 170 | </p> |
| 171 | <pre class="code"> |
| 172 | MACOSX_DEPLOYMENT_TARGET=XX.YY make |
| 173 | </pre> |
| 174 | <h3>Installing LuaJIT</h3> |
| 175 | <p> |
| 176 | The top-level Makefile installs LuaJIT by default under |
| 177 | <tt>/usr/local</tt>, i.e. the executable ends up in |
| 178 | <tt>/usr/local/bin</tt> and so on. You need root privileges |
| 179 | to write to this path. So, assuming sudo is installed on your system, |
| 180 | run the following command and enter your sudo password: |
| 181 | </p> |
| 182 | <pre class="code"> |
| 183 | sudo make install |
| 184 | </pre> |
| 185 | <p> |
| 186 | Otherwise specify the directory prefix as an absolute path, e.g.: |
| 187 | </p> |
| 188 | <pre class="code"> |
| 189 | make install PREFIX=/home/myself/lj2 |
| 190 | </pre> |
| 191 | <p> |
| 192 | Obviously the prefixes given during build and installation need to be the same. |
| 193 | </p> |
| 194 | |
| 195 | <h2 id="windows">Windows Systems</h2> |
| 196 | <h3>Prerequisites</h3> |
| 197 | <p> |
| 198 | Either install one of the open source SDKs |
| 199 | (<a href="http://mingw.org/"><span class="ext">»</span> MinGW</a> or |
| 200 | <a href="https://www.cygwin.com/"><span class="ext">»</span> Cygwin</a>), which come with a modified |
| 201 | GCC plus the required development headers. |
| 202 | Or install Microsoft's Visual Studio (MSVC). |
| 203 | </p> |
| 204 | <h3>Building with MSVC</h3> |
| 205 | <p> |
| 206 | Open a "Visual Studio Command Prompt" (x86, x64 or ARM64), <tt>cd</tt> to the |
| 207 | directory with the source code and run these commands: |
| 208 | </p> |
| 209 | <pre class="code"> |
| 210 | cd src |
| 211 | msvcbuild |
| 212 | </pre> |
| 213 | <p> |
| 214 | Check the <tt>msvcbuild.bat</tt> file for more options. |
| 215 | Then follow the installation instructions below. |
| 216 | </p> |
| 217 | <p> |
| 218 | For an x64 to ARM64 cross-build run this first: <tt>vcvarsall.bat x64_arm64</tt> |
| 219 | </p> |
| 220 | <h3>Building with MinGW or Cygwin</h3> |
| 221 | <p> |
| 222 | Open a command prompt window and make sure the MinGW or Cygwin programs |
| 223 | are in your path. Then <tt>cd</tt> to the directory of the git repository. |
| 224 | Then run this command for MinGW: |
| 225 | </p> |
| 226 | <pre class="code"> |
| 227 | mingw32-make |
| 228 | </pre> |
| 229 | <p> |
| 230 | Or this command for Cygwin: |
| 231 | </p> |
| 232 | <pre class="code"> |
| 233 | make |
| 234 | </pre> |
| 235 | <p> |
| 236 | Then follow the installation instructions below. |
| 237 | </p> |
| 238 | <h3>Installing LuaJIT</h3> |
| 239 | <p> |
| 240 | Copy <tt>luajit.exe</tt> and <tt>lua51.dll</tt> (built in the <tt>src</tt> |
| 241 | directory) to a newly created directory (any location is ok). |
| 242 | Add <tt>lua</tt> and <tt>lua\jit</tt> directories below it and copy |
| 243 | all Lua files from the <tt>src\jit</tt> directory of the distribution |
| 244 | to the latter directory. |
| 245 | </p> |
| 246 | <p> |
| 247 | There are no hardcoded |
| 248 | absolute path names — all modules are loaded relative to the |
| 249 | directory where <tt>luajit.exe</tt> is installed |
| 250 | (see <tt>src/luaconf.h</tt>). |
| 251 | </p> |
| 252 | |
| 253 | <h2 id="cross">Cross-compiling LuaJIT</h2> |
| 254 | <p> |
| 255 | First, let's clear up some terminology: |
| 256 | </p> |
| 257 | <ul> |
| 258 | <li>Host: This is your development system, usually based on a x64 or x86 CPU.</li> |
| 259 | <li>Target: This is the target system you want LuaJIT to run on, e.g. Android/ARM.</li> |
| 260 | <li>Toolchain: This comprises a C compiler, linker, assembler and a matching C library.</li> |
| 261 | <li>Host (or system) toolchain: This is the toolchain used to build native binaries for your host system.</li> |
| 262 | <li>Cross-compile toolchain: This is the toolchain used to build binaries for the target system. They can only be run on the target system.</li> |
| 263 | </ul> |
| 264 | <p> |
| 265 | The GNU Makefile-based build system allows cross-compiling on any host |
| 266 | for any supported target: |
| 267 | </p> |
| 268 | <ul> |
| 269 | <li>Yes, you need a toolchain for both your host <em>and</em> your target!</li> |
| 270 | <li>Both host and target architectures must have the same pointer size.</li> |
| 271 | <li>E.g. if you want to cross-compile to a 32 bit target on a 64 bit host, you need to install the multilib development package (e.g. <tt>libc6-dev-i386</tt> on Debian/Ubuntu) and build a 32 bit host part (<tt>HOST_CC="gcc -m32"</tt>).</li> |
| 272 | <li>On some distro versions, multilib conflicts with cross-compilers. The workaround is to install the x86 cross-compiler package <tt>gcc-i686-linux-gnu</tt> and use it to build the host part (<tt>HOST_CC=i686-linux-gnu-gcc</tt>).</li> |
| 273 | <li>64 bit targets always require compilation on a 64 bit host.</li> |
| 274 | </ul> |
| 275 | <p> |
| 276 | You need to specify <tt>TARGET_SYS</tt> whenever the host OS and the |
| 277 | target OS differ, or you'll get assembler or linker errors: |
| 278 | </p> |
| 279 | <ul> |
| 280 | <li>E.g. if you're compiling on a Windows or macOS host for embedded Linux or Android, you need to add <tt>TARGET_SYS=Linux</tt> to the examples below.</li> |
| 281 | <li>For a minimal target OS, you may need to disable the built-in allocator in <tt>src/Makefile</tt> and use <tt>TARGET_SYS=Other</tt>.</li> |
| 282 | <li>Don't forget to specify the same <tt>TARGET_SYS</tt> for the install step, too.</li> |
| 283 | </ul> |
| 284 | <p> |
| 285 | Here are some examples where host and target have the same CPU: |
| 286 | </p> |
| 287 | <pre class="code"> |
| 288 | # Cross-compile to a 32 bit binary on a multilib x64 OS |
| 289 | make CC="gcc -m32" |
| 290 | |
| 291 | # Cross-compile on Debian/Ubuntu for Windows (mingw32 package) |
| 292 | make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows |
| 293 | </pre> |
| 294 | <p id="cross2"> |
| 295 | The <tt>CROSS</tt> prefix allows specifying a standard GNU cross-compile |
| 296 | toolchain (Binutils, GCC and a matching libc). The prefix may vary |
| 297 | depending on the <tt>--target</tt> the toolchain was built for (note the |
| 298 | <tt>CROSS</tt> prefix has a trailing <tt>"-"</tt>). The examples below |
| 299 | use the canonical toolchain triplets for Linux. |
| 300 | </p> |
| 301 | <p> |
| 302 | Since there's often no easy way to detect CPU features at runtime, it's |
| 303 | important to compile with the proper CPU or architecture settings: |
| 304 | </o> |
| 305 | <ul> |
| 306 | <li>The best way to get consistent results is to specify the correct settings when building the toolchain yourself.</li> |
| 307 | <li>For a pre-built, generic toolchain add <tt>-mcpu=...</tt> or <tt>-march=...</tt> and other necessary flags to <tt>TARGET_CFLAGS</tt>.</li> |
| 308 | <li>For ARM it's important to have the correct <tt>-mfloat-abi=...</tt> setting, too. Otherwise LuaJIT may not run at the full performance of your target CPU.</li> |
| 309 | <li>For MIPS it's important to select a supported ABI (o32 on MIPS32, n64 on MIPS64) and consistently compile your project either with hard-float or soft-float compiler settings.</li> |
| 310 | </ul> |
| 311 | <p> |
| 312 | Here are some examples for targets with a different CPU than the host: |
| 313 | </p> |
| 314 | <pre class="code"> |
| 315 | # ARM soft-float |
| 316 | make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \ |
| 317 | TARGET_CFLAGS="-mfloat-abi=soft" |
| 318 | |
| 319 | # ARM soft-float ABI with VFP (example for Cortex-A9) |
| 320 | make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \ |
| 321 | TARGET_CFLAGS="-mcpu=cortex-a9 -mfloat-abi=softfp" |
| 322 | |
| 323 | # ARM hard-float ABI with VFP (armhf, most modern toolchains) |
| 324 | make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabihf- |
| 325 | |
| 326 | # ARM64 |
| 327 | make CROSS=aarch64-linux-gnu- |
| 328 | |
| 329 | # PPC |
| 330 | make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu- |
| 331 | |
| 332 | # MIPS32 big-endian |
| 333 | make HOST_CC="gcc -m32" CROSS=mips-linux-gnu- |
| 334 | # MIPS32 little-endian |
| 335 | make HOST_CC="gcc -m32" CROSS=mipsel-linux-gnu- |
| 336 | |
| 337 | # MIPS64 big-endian |
| 338 | make CROSS=mips-linux- TARGET_CFLAGS="-mips64r2 -mabi=64" |
| 339 | # MIPS64 little-endian |
| 340 | make CROSS=mipsel-linux- TARGET_CFLAGS="-mips64r2 -mabi=64" |
| 341 | </pre> |
| 342 | <p> |
| 343 | 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>. |
| 344 | Please adapt the environment variables to match the install locations and the |
| 345 | desired target platform. E.g. Android 4.1 corresponds to ABI level 16. |
| 346 | </p> |
| 347 | <pre class="code"> |
| 348 | # Android/ARM64, aarch64, Android 5.0+ (L) |
| 349 | NDKDIR=/opt/android/ndk |
| 350 | NDKBIN=$NDKDIR/toolchains/llvm/prebuilt/linux-x86_64/bin |
| 351 | NDKCROSS=$NDKBIN/aarch64-linux-android- |
| 352 | NDKCC=$NDKBIN/aarch64-linux-android21-clang |
| 353 | make CROSS=$NDKCROSS \ |
| 354 | STATIC_CC=$NDKCC DYNAMIC_CC="$NDKCC -fPIC" \ |
| 355 | TARGET_LD=$NDKCC TARGET_AR="$NDKBIN/llvm-ar rcus" \ |
| 356 | TARGET_STRIP=$NDKBIN/llvm-strip |
| 357 | |
| 358 | # Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.1+ (JB) |
| 359 | NDKDIR=/opt/android/ndk |
| 360 | NDKBIN=$NDKDIR/toolchains/llvm/prebuilt/linux-x86_64/bin |
| 361 | NDKCROSS=$NDKBIN/arm-linux-androideabi- |
| 362 | NDKCC=$NDKBIN/armv7a-linux-androideabi16-clang |
| 363 | make HOST_CC="gcc -m32" CROSS=$NDKCROSS \ |
| 364 | STATIC_CC=$NDKCC DYNAMIC_CC="$NDKCC -fPIC" \ |
| 365 | TARGET_LD=$NDKCC TARGET_AR="$NDKBIN/llvm-ar rcus" \ |
| 366 | TARGET_STRIP=$NDKBIN/llvm-strip |
| 367 | </pre> |
| 368 | <p> |
| 369 | You can cross-compile for <b id="ios">iOS 3.0+</b> (iPhone/iPad) using the <a href="https://developer.apple.com/ios/"><span class="ext">»</span> iOS SDK</a>: |
| 370 | </p> |
| 371 | <p style="font-size: 8pt;"> |
| 372 | Note: <b>the JIT compiler is disabled for iOS</b>, because regular iOS Apps |
| 373 | are not allowed to generate code at runtime. You'll only get the performance |
| 374 | of the LuaJIT interpreter on iOS. This is still faster than plain Lua, but |
| 375 | much slower than the JIT compiler. Please complain to Apple, not me. |
| 376 | Or use Android. :-p |
| 377 | </p> |
| 378 | <pre class="code"> |
| 379 | # iOS/ARM64 |
| 380 | ISDKP=$(xcrun --sdk iphoneos --show-sdk-path) |
| 381 | ICC=$(xcrun --sdk iphoneos --find clang) |
| 382 | ISDKF="-arch arm64 -isysroot $ISDKP" |
| 383 | make DEFAULT_CC=clang CROSS="$(dirname $ICC)/" \ |
| 384 | TARGET_FLAGS="$ISDKF" TARGET_SYS=iOS |
| 385 | </pre> |
| 386 | |
| 387 | <h3 id="consoles">Cross-compiling for consoles</h3> |
| 388 | <p> |
| 389 | Building LuaJIT for consoles requires both a supported host compiler |
| 390 | (x86 or x64) and a cross-compiler from the official console SDK. |
| 391 | </p> |
| 392 | <p> |
| 393 | Due to restrictions on consoles, the JIT compiler is disabled and only |
| 394 | the fast interpreter is built. This is still faster than plain Lua, |
| 395 | but much slower than the JIT compiler. The FFI is disabled, too, since |
| 396 | it's not very useful in such an environment. |
| 397 | </p> |
| 398 | <p> |
| 399 | The following commands build a static library <tt>libluajit.a</tt>, |
| 400 | which can be linked against your game, just like the Lua library. |
| 401 | </p> |
| 402 | <p> |
| 403 | To cross-compile for <b id="ps3">PS3</b> from a Linux host (requires |
| 404 | 32 bit GCC, i.e. multilib Linux/x64) or a Windows host (requires |
| 405 | 32 bit MinGW), run this command: |
| 406 | </p> |
| 407 | <pre class="code"> |
| 408 | make HOST_CC="gcc -m32" CROSS=ppu-lv2- |
| 409 | </pre> |
| 410 | <p> |
| 411 | To cross-compile for the other consoles from a Windows host, open a |
| 412 | "Native Tools Command Prompt for VS". You need to choose either the 32 |
| 413 | or the 64 bit version of the host compiler to match the target. |
| 414 | Then <tt>cd</tt> to the <tt>src</tt> directory below the source code |
| 415 | and run the build command given in the table: |
| 416 | </p> |
| 417 | <table class="compat"> |
| 418 | <tr class="compathead"> |
| 419 | <td class="compatname">Console</td> |
| 420 | <td class="compatbits">Bits</td> |
| 421 | <td class="compatx">Build Command</td> |
| 422 | </tr> |
| 423 | <tr class="odd separate"> |
| 424 | <td class="compatname"><b id="ps4">PS4</b></td> |
| 425 | <td class="compatbits">64</td> |
| 426 | <td class="compatx"><tt>ps4build</tt></td> |
| 427 | </tr> |
| 428 | <tr class="even"> |
| 429 | <td class="compatname"><b id="ps5">PS5</b></td> |
| 430 | <td class="compatbits">64</td> |
| 431 | <td class="compatx"><tt>ps5build</tt></td> |
| 432 | </tr> |
| 433 | <tr class="odd"> |
| 434 | <td class="compatname"><b id="psvita">PS Vita</b></td> |
| 435 | <td class="compatbits">32</td> |
| 436 | <td class="compatx"><tt>psvitabuild</tt></td> |
| 437 | </tr> |
| 438 | <tr class="even"> |
| 439 | <td class="compatname"><b id="xbox360">Xbox 360</b></td> |
| 440 | <td class="compatbits">32</td> |
| 441 | <td class="compatx"><tt>xedkbuild</tt></td> |
| 442 | </tr> |
| 443 | <tr class="odd"> |
| 444 | <td class="compatname"><b id="xboxone">Xbox One</b></td> |
| 445 | <td class="compatbits">64</td> |
| 446 | <td class="compatx"><tt>xb1build</tt></td> |
| 447 | </tr> |
| 448 | <tr class="even"> |
| 449 | <td class="compatname"><b id="nx32">Nintendo Switch NX32</b></td> |
| 450 | <td class="compatbits">32</td> |
| 451 | <td class="compatx"><tt>nxbuild</tt></td> |
| 452 | </tr> |
| 453 | <tr class="odd"> |
| 454 | <td class="compatname"><b id="nx64">Nintendo Switch NX64</b></td> |
| 455 | <td class="compatbits">64</td> |
| 456 | <td class="compatx"><tt>nxbuild</tt></td> |
| 457 | </tr> |
| 458 | </table> |
| 459 | <p> |
| 460 | Please check out the comments in the corresponding <tt>*.bat</tt> |
| 461 | file for more options. |
| 462 | </p> |
| 463 | |
| 464 | <h2 id="embed">Embedding LuaJIT</h2> |
| 465 | <p> |
| 466 | LuaJIT is API-compatible with Lua 5.1. If you've already embedded Lua |
| 467 | into your application, you probably don't need to do anything to switch |
| 468 | to LuaJIT, except link with a different library: |
| 469 | </p> |
| 470 | <ul> |
| 471 | <li>It's strongly suggested to build LuaJIT separately using the supplied |
| 472 | build system. Please do <em>not</em> attempt to integrate the individual |
| 473 | source files into your build tree. You'll most likely get the internal build |
| 474 | dependencies wrong or mess up the compiler flags. Treat LuaJIT like any |
| 475 | other external library and link your application with either the dynamic |
| 476 | or static library, depending on your needs.</li> |
| 477 | <li>If you want to load C modules compiled for plain Lua |
| 478 | with <tt>require()</tt>, you need to make sure the public symbols |
| 479 | (e.g. <tt>lua_pushnumber</tt>) are exported, too: |
| 480 | <ul><li>On POSIX systems you can either link to the shared library |
| 481 | or link the static library into your application. In the latter case |
| 482 | you'll need to export all public symbols from your main executable |
| 483 | (e.g. <tt>-Wl,-E</tt> on Linux) and add the external dependencies |
| 484 | (e.g. <tt>-lm -ldl</tt> on Linux).</li> |
| 485 | <li>Since Windows symbols are bound to a specific DLL name, you need to |
| 486 | link to the <tt>lua51.dll</tt> created by the LuaJIT build (do not rename |
| 487 | the DLL). You may link LuaJIT statically on Windows only if you don't |
| 488 | intend to load Lua/C modules at runtime. |
| 489 | </li></ul> |
| 490 | </li> |
| 491 | </ul> |
| 492 | <p>Additional hints for initializing LuaJIT using the C API functions:</p> |
| 493 | <ul> |
| 494 | <li>Here's a |
| 495 | <a href="http://lua-users.org/wiki/SimpleLuaApiExample"><span class="ext">»</span> simple example</a> |
| 496 | for embedding Lua or LuaJIT into your application.</li> |
| 497 | <li>Make sure you use <tt>luaL_newstate</tt>. Avoid using |
| 498 | <tt>lua_newstate</tt>, since this uses the (slower) default memory |
| 499 | allocator from your system (no support for this on 64 bit architectures).</li> |
| 500 | <li>Make sure you use <tt>luaL_openlibs</tt> and not the old Lua 5.0 style |
| 501 | of calling <tt>luaopen_base</tt> etc. directly.</li> |
| 502 | <li>To change or extend the list of standard libraries to load, copy |
| 503 | <tt>src/lib_init.c</tt> to your project and modify it accordingly. |
| 504 | Make sure the <tt>jit</tt> library is loaded, or the JIT compiler |
| 505 | will not be activated.</li> |
| 506 | <li>The <tt>bit.*</tt> module for bitwise operations |
| 507 | is already built-in. There's no need to statically link |
| 508 | <a href="https://bitop.luajit.org/"><span class="ext">»</span> Lua BitOp</a> to your application.</li> |
| 509 | </ul> |
| 510 | |
| 511 | <h2 id="distro">Hints for Distribution Maintainers</h2> |
| 512 | <p> |
| 513 | The LuaJIT build system has extra provisions for the needs of most |
| 514 | POSIX-based distributions. If you're a package maintainer for |
| 515 | a distribution, <em>please</em> make use of these features and |
| 516 | avoid patching, subverting, autotoolizing or messing up the build system |
| 517 | in unspeakable ways. |
| 518 | </p> |
| 519 | <p> |
| 520 | There should be absolutely no need to patch <tt>luaconf.h</tt> or any |
| 521 | of the Makefiles. And please do not hand-pick files for your packages — |
| 522 | simply use whatever <tt>make install</tt> creates. There's a reason |
| 523 | for all the files <em>and</em> directories it creates. |
| 524 | </p> |
| 525 | <p> |
| 526 | The build system uses GNU make and auto-detects most settings based on |
| 527 | the host you're building it on. This should work fine for native builds, |
| 528 | even when sandboxed. You may need to pass some of the following flags to |
| 529 | <em>both</em> the <tt>make</tt> and the <tt>make install</tt> command lines |
| 530 | for a regular distribution build: |
| 531 | </p> |
| 532 | <ul> |
| 533 | <li><tt>PREFIX</tt> overrides the installation path and should usually |
| 534 | be set to <tt>/usr</tt>. Setting this also changes the module paths and |
| 535 | the paths needed to locate the shared library.</li> |
| 536 | <li><tt>DESTDIR</tt> is an absolute path which allows you to install |
| 537 | to a shadow tree instead of the root tree of the build system.</li> |
| 538 | <li><tt>MULTILIB</tt> sets the architecture-specific library path component |
| 539 | for multilib systems. The default is <tt>lib</tt>.</li> |
| 540 | <li>Have a look at the top-level <tt>Makefile</tt> and <tt>src/Makefile</tt> |
| 541 | for additional variables to tweak. The following variables <em>may</em> be |
| 542 | overridden, but it's <em>not</em> recommended, except for special needs |
| 543 | like cross-builds: |
| 544 | <tt>BUILDMODE, CC, HOST_CC, STATIC_CC, DYNAMIC_CC, CFLAGS, HOST_CFLAGS, |
| 545 | TARGET_CFLAGS, LDFLAGS, HOST_LDFLAGS, TARGET_LDFLAGS, TARGET_SHLDFLAGS, |
| 546 | TARGET_FLAGS, LIBS, HOST_LIBS, TARGET_LIBS, CROSS, HOST_SYS, TARGET_SYS |
| 547 | </tt></li> |
| 548 | </ul> |
| 549 | <p> |
| 550 | The build system has a special target for an amalgamated build, i.e. |
| 551 | <tt>make amalg</tt>. This compiles the LuaJIT core as one huge C file |
| 552 | and allows GCC to generate faster and shorter code. Alas, this requires |
| 553 | lots of memory during the build. This may be a problem for some users, |
| 554 | that's why it's not enabled by default. But it shouldn't be a problem for |
| 555 | most build farms. It's recommended that binary distributions use this |
| 556 | target for their LuaJIT builds. |
| 557 | </p> |
| 558 | <p> |
| 559 | The tl;dr version of the above: |
| 560 | </p> |
| 561 | <pre class="code"> |
| 562 | make amalg PREFIX=/usr && \ |
| 563 | make install PREFIX=/usr DESTDIR=/tmp/buildroot |
| 564 | </pre> |
| 565 | <p> |
| 566 | Finally, if you encounter any difficulties, please |
| 567 | <a href="contact.html">contact me</a> first, instead of releasing a broken |
| 568 | package onto unsuspecting users. Because they'll usually gonna complain |
| 569 | to me (the upstream) and not you (the package maintainer), anyway. |
| 570 | </p> |
| 571 | <br class="flush"> |
| 572 | </div> |
| 573 | <div id="foot"> |
| 574 | <hr class="hide"> |
| 575 | Copyright © 2005-2025 |
| 576 | <span class="noprint"> |
| 577 | · |
| 578 | <a href="contact.html">Contact</a> |
| 579 | </span> |
| 580 | </div> |
| 581 | </body> |
| 582 | </html> |