install.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  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-2010, 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">
  12. table.compat {
  13. line-height: 1.2;
  14. width: 35em;
  15. }
  16. tr.compathead td {
  17. font-weight: bold;
  18. }
  19. td.compatos {
  20. width: 40%;
  21. }
  22. td.compatcc {
  23. width: 30%;
  24. vertical-align: top;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div id="site">
  30. <a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
  31. </div>
  32. <div id="head">
  33. <h1>Installation</h1>
  34. </div>
  35. <div id="nav">
  36. <ul><li>
  37. <a href="luajit.html">LuaJIT</a>
  38. <ul><li>
  39. <a class="current" href="install.html">Installation</a>
  40. </li><li>
  41. <a href="running.html">Running</a>
  42. </li><li>
  43. <a href="api.html">API Extensions</a>
  44. </li></ul>
  45. </li><li>
  46. <a href="status.html">Status</a>
  47. <ul><li>
  48. <a href="changes.html">Changes</a>
  49. </li></ul>
  50. </li><li>
  51. <a href="faq.html">FAQ</a>
  52. </li><li>
  53. <a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
  54. </li></ul>
  55. </div>
  56. <div id="main">
  57. <p>
  58. LuaJIT is only distributed as a source package. This page explains
  59. how to build and install LuaJIT with different operating systems
  60. and C&nbsp;compilers.
  61. </p>
  62. <p>
  63. For the impatient (on POSIX systems):
  64. </p>
  65. <pre class="code">
  66. make &amp;&amp; sudo make install
  67. </pre>
  68. <p>
  69. LuaJIT currently builds out-of-the box on most x86 or x64 systems.
  70. Here's the compatibility matrix for the supported combinations of
  71. operating system, CPU and compilers:
  72. </p>
  73. <table class="compat">
  74. <tr class="compathead">
  75. <td class="compatos">Operating system</td>
  76. <td class="compatcc">x86 (32 bit)</td>
  77. <td class="compatcc">x64 (64 bit)</td>
  78. </tr>
  79. <tr class="odd separate">
  80. <td class="compatos">Linux</td>
  81. <td class="compatcc">GCC 4.x<br>GCC 3.4</td>
  82. <td class="compatcc">GCC 4.x</td>
  83. </tr>
  84. <tr class="even">
  85. <td class="compatos">Windows 98/XP/Vista/7</td>
  86. <td class="compatcc">MSVC (EE)<br>Windows SDK<br>MinGW (GCC)<br>Cygwin (GCC)</td>
  87. <td class="compatcc">MSVC<br>Windows SDK</td>
  88. </tr>
  89. <tr class="odd">
  90. <td class="compatos">OSX 10.3-10.6</td>
  91. <td class="compatcc">GCC 4.x<br>GCC 3.4</td>
  92. <td class="compatcc">GCC 4.x</td>
  93. </tr>
  94. <tr class="even">
  95. <td class="compatos">*BSD, other</td>
  96. <td class="compatcc">GCC 4.x<br>GCC 3.4</td>
  97. <td class="compatcc">(not supported)</td>
  98. </tr>
  99. </table>
  100. <h2>Configuring LuaJIT</h2>
  101. <p>
  102. The standard configuration should work fine for most installations.
  103. Usually there is no need to tweak the settings. The following files
  104. hold all user-configurable settings:
  105. </p>
  106. <ul>
  107. <li><tt>src/luaconf.h</tt> sets some configuration variables.</li>
  108. <li><tt>Makefile</tt> has settings for <b>installing</b> LuaJIT (POSIX
  109. only).</li>
  110. <li><tt>src/Makefile</tt> has settings for <b>compiling</b> LuaJIT
  111. under POSIX, MinGW and Cygwin.</li>
  112. <li><tt>src/msvcbuild.bat</tt> has settings for compiling LuaJIT with
  113. MSVC.</li>
  114. </ul>
  115. <p>
  116. Please read the instructions given in these files, before changing
  117. any settings.
  118. </p>
  119. <h2 id="posix">POSIX Systems (Linux, OSX, *BSD etc.)</h2>
  120. <h3>Prerequisites</h3>
  121. <p>
  122. Depending on your distribution, you may need to install a package for
  123. GCC (GCC 3.4 or later required), the development headers and/or a
  124. complete SDK. E.g. on a current Debian/Ubuntu, install <tt>libc6-dev</tt>
  125. with the package manager.
  126. </p>
  127. <p>
  128. Download the current source package (pick the .tar.gz), if you haven't
  129. already done so. Move it to a directory of your choice, open a
  130. terminal window and change to this directory. Now unpack the archive
  131. and change to the newly created directory:
  132. </p>
  133. <pre class="code">
  134. tar zxf LuaJIT-2.0.0-beta3.tar.gz
  135. cd LuaJIT-2.0.0-beta3</pre>
  136. <h3>Building LuaJIT</h3>
  137. <p>
  138. The supplied Makefiles try to auto-detect the settings needed for your
  139. operating system and your compiler. They need to be run with GNU Make,
  140. which is probably the default on your system, anyway. Simply run:
  141. </p>
  142. <pre class="code">
  143. make
  144. </pre>
  145. <p>
  146. This always builds a native x86 or x64 binary, depending on your OS.
  147. </p>
  148. <p>
  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.:
  152. </p>
  153. <pre class="code">
  154. make PREFIX=/home/myself/lj2
  155. </pre>
  156. <p>
  157. Note for OSX: <tt>MACOSX_DEPLOYMENT_TARGET</tt> is set to <tt>10.4</tt>
  158. in <tt>src/Makefile</tt>. Change it, if you want to build on an older version.
  159. </p>
  160. <h3>Installing LuaJIT</h3>
  161. <p>
  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:
  167. </p>
  168. <pre class="code">
  169. sudo make install
  170. </pre>
  171. <p>
  172. Otherwise specify the directory prefix as an absolute path, e.g.:
  173. </p>
  174. <pre class="code">
  175. make install PREFIX=/home/myself/lj2
  176. </pre>
  177. <p>
  178. Obviously the prefixes given during build and installation need to be the same.
  179. </p>
  180. <p style="color: #c00000;">
  181. Note: to avoid overwriting a previous version, the beta test releases
  182. only install the LuaJIT executable under the versioned name (i.e.
  183. <tt>luajit-2.0.0-beta3</tt>). You probably want to create a symlink
  184. for convenience, with a command like this:
  185. </p>
  186. <pre class="code" style="color: #c00000;">
  187. sudo ln -sf luajit-2.0.0-beta3&nbsp;/usr/local/bin/luajit
  188. </pre>
  189. <h2 id="windows">Windows Systems</h2>
  190. <h3>Prerequisites</h3>
  191. <p>
  192. Either install one of the open source SDKs
  193. (<a href="http://mingw.org/"><span class="ext">&raquo;</span>&nbsp;MinGW</a> or
  194. <a href="http://www.cygwin.com/"><span class="ext">&raquo;</span>&nbsp;Cygwin</a>), which come with a modified
  195. GCC plus the required development headers.
  196. </p>
  197. <p>
  198. Or install Microsoft's Visual C++ (MSVC). The freely downloadable
  199. <a href="http://www.microsoft.com/Express/VC/"><span class="ext">&raquo;</span>&nbsp;Express Edition</a>
  200. works just fine, but only contains an x86 compiler.
  201. </p>
  202. <p>
  203. The freely downloadable
  204. <a href="http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx"><span class="ext">&raquo;</span>&nbsp;Windows SDK</a>
  205. only comes with command line tools, but this is all you need to build LuaJIT.
  206. It contains x86 and x64 compilers.
  207. </p>
  208. <p>
  209. Next, download the source package and unpack it using an archive manager
  210. (e.g. the Windows Explorer) to a directory of your choice.
  211. </p>
  212. <h3>Building with MSVC</h3>
  213. <p>
  214. Open a "Visual Studio .NET Command Prompt", <tt>cd</tt> to the
  215. directory where you've unpacked the sources and run these commands:
  216. </p>
  217. <pre class="code">
  218. cd src
  219. msvcbuild
  220. </pre>
  221. <p>
  222. Then follow the installation instructions below.
  223. </p>
  224. <h3>Building with the Windows SDK</h3>
  225. <p>
  226. Open a "Windows SDK Command Shell" and select the x86 compiler:
  227. </p>
  228. <pre class="code">
  229. setenv /release /x86
  230. </pre>
  231. <p>
  232. Or select the x64 compiler:
  233. </p>
  234. <pre class="code">
  235. setenv /release /x64
  236. </pre>
  237. <p>
  238. Then <tt>cd</tt> to the directory where you've unpacked the sources
  239. and run these commands:
  240. </p>
  241. <pre class="code">
  242. cd src
  243. msvcbuild
  244. </pre>
  245. <p>
  246. Then follow the installation instructions below.
  247. </p>
  248. <h3>Building with MinGW or Cygwin</h3>
  249. <p>
  250. Open a command prompt window and make sure the MinGW or Cygwin programs
  251. are in your path. Then <tt>cd</tt> to the directory where
  252. you've unpacked the sources and run this command for MinGW:
  253. </p>
  254. <pre class="code">
  255. mingw32-make
  256. </pre>
  257. <p>
  258. Or this command for Cygwin:
  259. </p>
  260. <pre class="code">
  261. make
  262. </pre>
  263. <p>
  264. Then follow the installation instructions below.
  265. </p>
  266. <h3>Installing LuaJIT</h3>
  267. <p>
  268. Copy <tt>luajit.exe</tt> and <tt>lua51.dll</tt> (built in the <tt>src</tt>
  269. directory) to a newly created directory (any location is ok).
  270. Add <tt>lua</tt> and <tt>lua\jit</tt> directories below it and copy
  271. all Lua files from the <tt>lib</tt> directory of the distribution
  272. to the latter directory.
  273. </p>
  274. <p>
  275. There are no hardcoded
  276. absolute path names &mdash; all modules are loaded relative to the
  277. directory where <tt>luajit.exe</tt> is installed
  278. (see <tt>src/luaconf.h</tt>).
  279. </p>
  280. <h2>Cross-compiling LuaJIT</h2>
  281. <p>
  282. The build system has limited support for cross-compilation. For details
  283. check the comments in <tt>src/Makefile</tt>. Here are some popular examples:
  284. </p>
  285. <p>
  286. You can cross-compile to a 32 bit binary on a multilib x64 OS by
  287. installing the multilib development packages (e.g. <tt>libc6-dev-i386</tt>
  288. on Debian/Ubuntu) and running:
  289. </p>
  290. <pre class="code">
  291. make CC="gcc -m32"
  292. </pre>
  293. <p>
  294. You can cross-compile for a Windows target on Debian/Ubuntu by
  295. installing the <tt>mingw32</tt> package and running:
  296. </p>
  297. <pre class="code">
  298. make CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
  299. </pre>
  300. <h2>Embedding LuaJIT</h2>
  301. <p>
  302. LuaJIT is API-compatible with Lua 5.1. If you've already embedded Lua
  303. into your application, you probably don't need to do anything to switch
  304. to LuaJIT, except link with a different library. Additional hints:
  305. </p>
  306. <ul>
  307. <li>Make sure you use <tt>luaL_newstate</tt>. Avoid using
  308. <tt>lua_newstate</tt>, since this uses the (slower) default memory
  309. allocator from your system (no support for this on x64).</tt></li>
  310. <li>Make sure you use <tt>luaL_openlibs</tt> and not the old Lua 5.0 style
  311. of calling <tt>luaopen_base</tt> etc. directly.</li>
  312. <li>To change which standard libraries to load, copy <tt>src/lib_init.c</tt>
  313. to your project and modify it accordingly. Make sure the <tt>jit</tt>
  314. library is loaded or the JIT compiler will not be activated.</li>
  315. <li>Here's a
  316. <a href="http://lua-users.org/wiki/SimpleLuaApiExample"><span class="ext">&raquo;</span>&nbsp;simple example</a>.</li>
  317. </ul>
  318. <p>
  319. 64 bit applications on OSX must be linked with these options
  320. (only the main executable):
  321. </p>
  322. <pre class="code">
  323. -pagezero_size 10000 -image_base 100000000
  324. </pre>
  325. <p>
  326. It's recommended to <tt>rebase</tt> all (self-compiled) shared libraries
  327. which are loaded at runtime on OSX/x64 (e.g. C extension modules for Lua).
  328. See: <tt>man rebase</tt>
  329. </p>
  330. <br class="flush">
  331. </div>
  332. <div id="foot">
  333. <hr class="hide">
  334. Copyright &copy; 2005-2010 Mike Pall
  335. <span class="noprint">
  336. &middot;
  337. <a href="contact.html">Contact</a>
  338. </span>
  339. </div>
  340. </body>
  341. </html>