How to build C program that emedded Lua -


i'm learning how embed lua c, , start simple example:

demo.c

#include <stdio.h> #include <string.h> #include <lua.h> #include <lauxlib.h> #include <lualib.h>  int main (void) {     char buff[256];     int error;     lua_state *l = lual_newstate();   /* opens lua */     luaopen_base(l);             /* opens basic library */     luaopen_table(l);            /* opens table library */     luaopen_io(l);               /* opens i/o library */     luaopen_string(l);           /* opens string lib. */     luaopen_math(l);             /* opens 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 stack */         }     }      lua_close(l);     return 0; } 

======

my local environment:

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 

then:

gcc -o demo demo.c -llua5.2 demo.c:3:17: fatal error: lua.h: no such file or directory compilation terminated. 

i tried -llua5, -llua , failed.

====== found solution:

gcc -o demo demo.c -i/usr/include/lua5.2 /usr/lib/i386-linux-gnu/liblua5.2.a -lm 

but couldn't figure out why cannot usual.

you need either specify actual path header file:

#include <lua5.2/lua.h> 

or use -i/usr/include/lua5.2, figured out. when attempt include <lua.h>, compiler looks @ /usr/include/lua.h (and few other places don't matter here).


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -