title: embedding luajit undefined reference
body: <p>I'm unsuccessfully trying to embed (statically) luajit into a c++ application. I have followed the steps from the luajit site to no avail, googled on the subject and got no relevant information and tried every thing I could think of.</p>
  
  <p>It appears as if the problem I'm running in is that g++ doesn't quite link it properly, or perhaps luajit ins't building properly.</p>
  
  <p>This is what I'm trying to compile:</p>
  
  <pre><code>#include &lt;lua.h&gt;
  #include &lt;lauxlib.h&gt;
  #include &lt;lualib.h&gt;
  
  int main(void)
  {
      lua_State *L = luaL_newstate();
      luaL_openlibs(L);
      lua_close(L);
  
      return 0;
  }
  </code></pre>
  
  <p>And the error I'm getting is a <code>undefined reference</code> error almost as if I hadn't linked luajit at all.</p>
  
  <pre><code>main.cpp:7: undefined reference to `luaL_newstate()'
  main.cpp:9: undefined reference to `luaL_openlibs(lua_State*)'
  main.cpp:10: undefined reference to `lua_close(lua_State*)'
  </code></pre>
  
  <p>I'm trying to compile it with eclipse cdt (mingw) after setting the linking options as following:</p>
  
  <pre><code>Library Paths:        D:/includes/LuaJIT-2.0.1/src
  Includes (GNU G++):   D:/includes/LuaJIT-2.0.1/src
  Libraries:            luajit
  </code></pre>
  
  <p>And eclipse cdt appears to be trying to compile it as following:</p>
  
  <pre><code>g++ -ID:/includes/LuaJIT-2.0.1/src -O0 -g3 -pedantic-errors -Wall -Wextra -Werror -Wconversion -c -fmessage-length=0 -Weffc++ -std=c++11 -o "source\\main.o" "..\\source\\main.cpp" 
  g++ -LD:/includes/LuaJIT-2.0.1/src -o test.exe "source\\main.o" -lluajit
  </code></pre>
  
  <p>I have downloaded <a href="http://luajit.org/download/LuaJIT-2.0.1.zip" rel="nofollow">LuaJIT-2.0.1 zip</a> (latest version) from their <a href="http://luajit.org/download.html" rel="nofollow">download page</a> and followed the <a href="http://luajit.org/install.html" rel="nofollow">installation guide</a> as following:</p>
  
  <ul>
  <li>Unziped it.</li>
  <li>Fired up a cmd and cded to <code>LuaJIT-2.0.1/src/</code></li>
  <li>Ran <code>make BUILDMODE=static</code> and got a nice <code>OK Successfully built LuaJIT</code> message</li>
  </ul>
  
  <p>Other than that there ins't a lot of information on embedding luajit, not even in the <a href="http://luajit.org/install.html#embed" rel="nofollow">installation guide</a>.</p>
  
  <p>However grepping the <code>src</code> folder for <code>luaL_newstate</code> returns a match in the <code>libluajit.a</code>.</p>
  
  <pre><code>grep -r "luaL_newstate" .
  
  ./host/genminilua.lua:  lua_State *L = luaL_newstate();
  ./host/minilua.c:static lua_State*luaL_newstate(void){
  ./host/minilua.c:lua_State*L=luaL_newstate();
  ./lauxlib.h:LUALIB_API lua_State *(luaL_newstate) (void);
  Binary file ./libluajit.a matches
  ./lib_aux.c:LUALIB_API lua_State *luaL_newstate(void)
  ./lib_aux.c:LUALIB_API lua_State *luaL_newstate(void)
  ./lib_aux.c:  fputs("Must use luaL_newstate() for 64 bit target\n", stderr);
  Binary file ./lib_aux.o matches
  ./lua.h:#define lua_open()      luaL_newstate()
  Binary file ./luajit.exe matches
  Binary file ./luajit.o matches
  </code></pre>
  
  <p>I'm using:</p>
  
  <ul>
  <li>mingw's <code>g++ (rev, Built by MinGW-builds project) 4.8.0 20130314 (experimental)</code></li>
  <li>mingw's <code>GNU Make 3.82.90 Built for i686-pc-msys</code></li>
  <li>Win8 64bit</li>
  </ul>