lua-users home
lua-l archive

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




> You might need to add something like:
> -Wl,-E -llua
> to the linker flags when you build your application.
>
> - Jeff

Thank You,
Still stumped on using require from embedded c++.
Using linker options -Wl, -E -llua...
I'm not sure to which line, etc. the following output is referring.

./hello: line 33: extern: command not found
./hello: line 39: typedef: command not found
./hello: line 48: typedef: command not found
./hello: line 49: typedef: command not found
./hello: line 50: typedef: command not found
./hello: line 51: typedef: command not found
./hello: line 54: typedef: command not found
./hello: line 55: typedef: command not found
./hello: line 56: typedef: command not found
./hello: line 57: typedef: command not found
./hello: line 58: typedef: command not found
./hello: line 59: typedef: command not found
./hello: line 64: __extension__: command not found
./hello: line 65: __extension__: command not found
./hello: line 73: __extension__: command not found
./hello: line 74: __extension__: command not found
./hello: line 80: __extension__: command not found
./hello: line 81: __extension__: command not found
./hello: line 82: __extension__: command not found
./hello: line 83: __extension__: command not found
./hello: line 84: __extension__: command not found
./hello: line 85: __extension__: command not found
./hello: line 86: __extension__: command not found
./hello: line 87: __extension__: command not found
./hello: line 88: __extension__: command not found
./hello: line 89: __extension__: command not found
./hello: line 90: syntax error near unexpected token `}'
./hello: line 90: `__extension__ typedef struct { int __val[2]; } __fsid_t;'
------------
linux f10, g++, Lua-5.1.4, lua rock -random

I did make on Lua-5.1.4 srcs, also make on random srcs
Pure Lua works fine for 'require'.

Embedded Lua only works if I compile hello.cpp inside the folder
which contains  the random.so.

I cannot seem to get require to work from lua in embedded c++ from any other directory.

I've tried a bash script to set paths to LUA_PATH, and LUA_CPATH, I tried
setting the full path in 'require' which gives compile error.

Since new to Lua, I'm confused how to see require working. 

--hello.lua
require"random"
print(random.version)


//hello.cpp
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cstdlib>

extern "C" {
    #include "lua.h"
    #include "lualib.h"
    #include "lauxlib.h"
}

lua_State* L;
int main (int argc, char *argv[])
{
int status;
    L = luaL_newstate();
    luaL_openlibs(L);
        status = luaL_loadfile(L, "/mypathto/hello.lua");

    if (status) {
        fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
        exit(1);
    }

    luaL_dofile(L,"/mypathto/hello.lua");

    lua_close(L);

    return 0;
}

Compiled above code from inside the lua-5.1.4 src dir where lua binary resides, and it still cannot find the random lib when running exe.

>g++ hello.cpp -o hello -I/mypathto/random -L/mypathto/random -Wl, -E -llua



Hotmail: Powerful Free email with security by Microsoft. Get it now.