Results 1 to 7 of 7

Thread: Embedding LUA to C++ - Missing headers while compiling?

  1. #1
    Join Date
    Aug 2009
    Location
    Mar del Plata, Argentina
    Beans
    81
    Distro
    Ubuntu 11.04 Natty Narwhal

    Unhappy Embedding LUA to C++ - Missing headers while compiling?

    Well, I was wondering how to embed a scripting language into C++ so I did a search and I find out this tutorial, I installed the required libraries and anything that said LUA and DEV in Synaptics... But, I can't manage to compile it...

    Here is the code from the tutorial:

    Code:
    #include <stdio.h>
    
    #include "lua.h"
    #include "lualib.h"
    #include "lauxlib.h"  /* the Lua interpreter */
    
    lua_State* L; 
    
    int main ( int argc, char *argv[] ) {
       /* initialize Lua */
       L = lua_open();
       /* load various Lua libraries */
       lua_baselibopen(L); 
       luaopen_table(L);
       luaopen_io(L);
       luaopen_string(L);
       luaopen_math(L);
    
       /* cleanup Lua */
       lua_close(L);
       return 0;
    }
    First of all: Why it uses #include "***" instead of #include <***>? It want me to copy the headers from the system libraries to my program path? :S. Anyway if I change it to <***> it doesn't find anything neither:

    Code:
    zequez@zequez-desktop:$ gcc main.cpp
    main.cpp:3:17: error: lua.h: No such file or directory
    main.cpp:4:20: error: lualib.h: No such file or directory
    main.cpp:5:21: error: lauxlib.h: No such file or directory
    main.cpp:8: error: expected constructor, destructor, or type conversion before ‘*’ token
    main.cpp: In function ‘int main(int, char**)’:
    main.cpp:12: error: ‘L’ was not declared in this scope
    main.cpp:12: error: ‘lua_open’ was not declared in this scope
    main.cpp:15: error: ‘lua_baselibopen’ was not declared in this scope
    main.cpp:16: error: ‘luaopen_table’ was not declared in this scope
    main.cpp:17: error: ‘luaopen_io’ was not declared in this scope
    main.cpp:18: error: ‘luaopen_string’ was not declared in this scope
    main.cpp:19: error: ‘luaopen_math’ was not declared in this scope
    main.cpp:22: error: ‘lua_close’ was not declared in this scope
    zequez@zequez-desktop:$
    Which are the links for LUA? And what means the return of lua-config?
    Last edited by ZequeZ; August 16th, 2010 at 09:56 PM.

  2. #2
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,288
    Distro
    Kubuntu

    Re: Embedding LUA to C++ - Missing headers while compiling?

    You tell me... do you have the LUA header files on your system???????????????

    If you don't, get them. If you do, then where are they? Find out. Let us know... then we can help you with your g++ statement.

    C --> use gcc

    C++ --> use g++


    Note: C and C++ are NOT the same. C is a very basic language.

  3. #3
    Join Date
    Aug 2009
    Location
    Mar del Plata, Argentina
    Beans
    81
    Distro
    Ubuntu 11.04 Natty Narwhal

    Talking Re: Embedding LUA to C++ - Missing headers while compiling?

    Quote Originally Posted by dwhitney67 View Post
    You tell me... do you have the LUA header files on your system???????????????

    If you don't, get them. If you do, then where are they? Find out. Let us know... then we can help you with your g++ statement.

    C --> use gcc

    C++ --> use g++


    Note: C and C++ are NOT the same. C is a very basic language.
    Wait... gcc doesn't compile C++? Damn, that explain a lot of things *facepalm*

  4. #4

    Re: Embedding LUA to C++ - Missing headers while compiling?

    Hi,

    First, it's Lua, not LUA (it's not an acronym, it's the portuguese for moon).

    Here goes a simple example of how to use Lua with C++:

    PHP Code:
    extern "C" {
        
    #include <lua.h>
        #include <lauxlib.h>
        #include <lualib.h>
    }

    int main(int argcchar** argv)
    {
        
    lua_StateluaL_newstate();
        
        
    luaL_dostring(L"a = 10 + 5");
        
    lua_getglobal(L"a");
        
    int i lua_tointeger(L, -1);
        
    printf("%d\n"i);
        
        
    lua_close(L);
        
        return 
    0;

    You can compile it with 'g++ test.cpp -o output -llua'.
    If you still get those errors, then you don't have the headers.

  5. #5
    Join Date
    Aug 2007
    Beans
    949

    Re: Embedding LUA to C++ - Missing headers while compiling?

    Quote Originally Posted by ZequeZ View Post
    Wait... gcc doesn't compile C++? Damn, that explain a lot of things *facepalm*
    It actually just invokes the C++ compiler if you try to feed it C++ code.

  6. #6
    Join Date
    Aug 2009
    Location
    Mar del Plata, Argentina
    Beans
    81
    Distro
    Ubuntu 11.04 Natty Narwhal

    Smile Re: Embedding LUA to C++ - Missing headers while compiling?

    Thanks ^^.
    But still having trouble to compile successful =(.
    I installed everything that has lua and dev in the name and then I used lua-config --libs to see which libraries I had to use to compile and then I used lua-config --include to see the path where Lua is located, buuut it still don't compile =(.

    Here is what I have:

    Code:
    extern "C" {
        #include <lua50/lua.h>
        #include <lua50/lauxlib.h>
        #include <lua50/lualib.h>
    }
    
    int main(int argc, char** argv)
    {
        lua_State* L = luaL_newstate();
        
        luaL_dostring(L, "a = 10 + 5");
        lua_getglobal(L, "a");
        int i = lua_tointeger(L, -1);
        printf("%d\n", i);
        
        lua_close(L);
        
        return 0;
    }

    Code:
    zequez@zequez:~/Lua$ lua-config --libs
    -L/usr/include -llualib50 -llua50
    zequez@zequez:~/Lua$ lua-config --include
    -I/usr/include/lua50
    zequez@zequez:~/Lua$ g++ main.cpp -llua50 -llualib50
    main.cpp: In function ‘int main(int, char**)’:
    main.cpp:9: error: ‘luaL_newstate’ was not declared in this scope
    main.cpp:11: error: ‘luaL_dostring’ was not declared in this scope
    main.cpp:13: error: ‘lua_tointeger’ was not declared in this scope
    Any clue?

    Sorry for my English =P

  7. #7

    Re: Embedding LUA to C++ - Missing headers while compiling?

    Lua 5.0 doesn't have the functions 'luaL_newstate' and etc. This functions were added in version 5.1 (the current version, released in 2006).

    The official site is: http://www.lua.org

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •