Lua - 初始化

我在 Arch Linux 下无法正确初始化 Lua,使用的是最新版本。下面是我的代码:

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

int main()
{
    lua_State *luaVM = luaL_newstate();
    if (luaVM == NULL)
    {
        printf("Error initializing lua!\n");
        return -1;
    }

    luaL_openlibs(luaVM);
    lua_close(luaVM);

    return 0;
}

出现以下错误:

/tmp/cc0iJ6lW.o: In function main': test_lua.cpp:(.text+0xa): undefined reference to luaL_newstate'

test_lua.cpp:(.text+0x34): undefined reference to `luaL_openlibs'

test_lua.cpp:(.text+0x40): undefined reference to `lua_close' collect2: ld

returned 1 exit status

有什么问题吗?

原文链接 https://stackoverflow.com/questions/2441513

点赞
stackoverflow用户224671
stackoverflow用户224671

你需要通过传递 -llua-llualib 标志与 Lua 库链接。

2010-03-14 09:18:52