簡體   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