title: How to build C program with Lua
body: <p>test.c :</p>
  
  <pre><code>#include "lua.h"
  #include "lauxlib.h"
  #include "lualib.h"
  
  int main(){
  
    lua_State *L = luaL_newState();  /* opens Lua */
    luaL_openlibs(L);   /* opens the standard libraries */
  
    luaL_dofile(L,"test.lua"); /* runs Lua scrip */
  
    lua_close(L);
    return 0;
  
  }
  </code></pre>
  
  <p>build:</p>
  
  <pre><code>gcc -o test test.c -I/usr/local/Cellar/lua/5.1.5/include
  </code></pre>
  
  <p>then i got error:</p>
  
  <pre><code>test.c:7:18: warning: implicit declaration of function 'luaL_newState' is
        invalid in C99 [-Wimplicit-function-declaration]
    lua_State *L = luaL_newState();  /* opens Lua */
                   ^
  test.c:7:14: warning: incompatible integer to pointer conversion initializing
        'lua_State *' (aka 'struct lua_State *') with an expression of type 'int'
        [-Wint-conversion]
    lua_State *L = luaL_newState();  /* opens Lua */
               ^   ~~~~~~~~~~~~~~~
  2 warnings generated.
  Undefined symbols for architecture x86_64:
    "_luaL_loadfile", referenced from:
        _main in test-dxPwkn.o
    "_luaL_newState", referenced from:
        _main in test-dxPwkn.o
    "_luaL_openlibs", referenced from:
        _main in test-dxPwkn.o
    "_lua_close", referenced from:
        _main in test-dxPwkn.o
    "_lua_pcall", referenced from:
        _main in test-dxPwkn.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>I installed Lua via Homebrew:</p>
  
  <pre><code>ls /usr/local/Cellar/lua/5.1.5/include
  lauxlib.h lua.h     lua.hpp   luaconf.h lualib.h
  </code></pre>
  
  <p>Anyone knows how to solve this error? Thanks.</p>