繁体   English   中英

Lua 5.2:使用luaL_dofile()时未定义的符号

[英]Lua 5.2: undefined symbols when using luaL_dofile()

我试图使用以下C ++代码进行一些简单的Lua 5.2嵌入:

void dnLuaRunner::Exec(string file)
{
    // Initialize the lua interpreter.
    lua_State * L;
    L = luaL_newstate();

    // Load lua libraries.
    static const luaL_Reg luaLibs[] =
    {
        {"math", luaopen_math},
        {"base", luaopen_base},
        {NULL, NULL}
    };

    // Loop through all the functions in the array of library functions
    // and load them into the interpreter instance.
    const luaL_Reg * lib = luaLibs;
    for (; lib->func != NULL; lib++)
    {
        lib->func(L);
        lua_settop(L, 0);
    }

    // Run the file through the interpreter instance.
    luaL_dofile(L, file.c_str());

    // Free memory allocated by the interpreter instance.
    lua_close(L);
}

第一部分是一些基本的初始化和用于加载一些标准库模块的代码,但是当我调用luaL_dofile(...)它似乎为未定义的符号引发了一些错误。 luaL_dofile是一个使用luaL_loadfilelua_pcall等函数的宏,因此我收到以下链接器错误并不是非常可怕:

  "_luaL_loadfilex", referenced from:
      dnLuaRunner::Exec(std::string) in dnLuaRunner.cc.o
  "_lua_pcallk", referenced from:
      dnLuaRunner::Exec(std::string) in dnLuaRunner.cc.o
ld: symbol(s) not found for architecture x86_64

我正在Makefile中正确链接liblua.a

事实证明你需要添加-lm-llua ,它们都必须在你想要编译的文件之后,如下所示:

# or clang++ works too
$ g++ ... foofy.c -llua -lm

我也看到了你必须在最后使用-ldl情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM