install.html 10 KB

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