lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

I am running Ubuntu Linux and I wish to compile an application which only has a few lines of C and most of it is in Lua.

Although I am rather proficient in Lua, I am not proficient in C compiling and linking. I downloaded the Lua sources from the official site and then I tried the example from page 219 in PiL book:

    #include <stdio.h>
    #include "lua.h"
    #include "lauxlib.h"
    #include "lualib.h"
   
int main (void) {
    char buff[256];
      int error;
    lua_State *L = lua_open();   /* opens Lua */
    luaL_openlibs(L);
    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;
}

Then I tried compiling this with "gcc -I../lib/lua-5.1.4/src main.c -o emulator" and got the following errors:

main.c: In function ‘main’:
main.c:12: warning: incompatible implicit declaration of built-in function ‘strlen’
/tmp/ccsb4CUD.o: In function `main':
main.c:(.text+0x21): undefined reference to `luaL_newstate'
main.c:(.text+0x35): undefined reference to `luaL_openlibs'
main.c:(.text+0x6c): undefined reference to `luaL_loadbuffer'
main.c:(.text+0x96): undefined reference to `lua_pcall'
main.c:(.text+0xe9): undefined reference to `lua_tolstring'
main.c:(.text+0x10b): undefined reference to `lua_settop'
main.c:(.text+0x140): undefined reference to `lua_close'
collect2: ld returned 1 exit status

Now, I am not sure if this is some deeper problem or if I made some very basic mistake (again, I don't understand C compiling very much, I do most of my stuff in pure Lua) but it seems to me those "undefined" symbols are defined in ".h" files in lua-5.1.4/src/ directory.

Could you please enlighten me what command line options to create stand-alone executable from the example at page 219 using only the original Lua sources (not any pre-compiled libraries, it must be completely self-sufficient). Thank you very much.

--
Frantisek Fuka
(yes, that IS my real name)
(and it's pronounced "Fran-tjee-shek Foo-kah")

Jabber/GoogleTalk ID: fuka@fuxoft.cz
Homepage: http://www.fuxoft.cz