title: How to build C program that emedded Lua
body: <p>I'm learning how to embed Lua into C, and start with a simple example:</p>
  
  <p>demo.c</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;lua.h&gt;
  #include &lt;lauxlib.h&gt;
  #include &lt;lualib.h&gt;
  
  int main (void) {
      char buff[256];
      int error;
      lua_State *L = luaL_newstate();   /* opens Lua */
      luaopen_base(L);             /* opens the basic library */
      luaopen_table(L);            /* opens the table library */
      luaopen_io(L);               /* opens the I/O library */
      luaopen_string(L);           /* opens the string lib. */
      luaopen_math(L);             /* opens the math lib. */
  
      while (fgets(buff, sizeof(buff), stdin) != NULL) {
          error = luaL_loadbuffer(L, buff, strlen(buff), "line") ||
              lua_pcall(L, 0, 0, 0);
          if (error) {
              fprintf(stderr, "%s", lua_tostring(L, -1));
              lua_pop(L, 1);  /* pop error message from the stack */
          }
      }
  
      lua_close(L);
      return 0;
  }
  </code></pre>
  
  <p>======</p>
  
  <p>My Local environment:</p>
  
  <pre><code>evans@master:~/codebase/demo/lua$ sudo dpkg -L liblua5.2-dev
  /.
  /usr
  /usr/include
  /usr/include/lua5.2
  /usr/include/lua5.2/lua.h
  /usr/include/lua5.2/luaconf.h
  /usr/include/lua5.2/lualib.h
  /usr/include/lua5.2/lauxlib.h
  /usr/include/lua5.2/lua.hpp
  /usr/lib
  /usr/lib/i386-linux-gnu
  /usr/lib/i386-linux-gnu/liblua5.2.a
  /usr/lib/i386-linux-gnu/pkgconfig
  /usr/lib/i386-linux-gnu/pkgconfig/lua5.2.pc
  /usr/share
  /usr/share/doc
  /usr/share/doc/liblua5.2-dev
  /usr/share/doc/liblua5.2-dev/copyright
  /usr/lib/i386-linux-gnu/liblua5.2.so
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code>gcc -o demo demo.c -llua5.2
  demo.c:3:17: fatal error: lua.h: No such file or directory
  compilation terminated.
  </code></pre>
  
  <p>I also tried <code>-llua5</code>, <code>-llua</code> and all failed. </p>
  
  <p>======
  Finally I found a solution:</p>
  
  <pre><code>gcc -o demo demo.c -I/usr/include/lua5.2 /usr/lib/i386-linux-gnu/liblua5.2.a -lm
  </code></pre>
  
  <p><strong>But I couldn't figure out why I cannot do that as I usual.</strong></p>