Lua - 初始化

6

我在 Arch Linux 下无法正确地初始化 Lua。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 toluaL_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

出了什么问题?


5
你是否链接了 -llua-llualib - kennytm
忘记了 :( 谢谢。当主题中没有答案但问题已解决时该怎么办? - Max Frai
2
我猜要么等待KennyTM把它放在答案中,要么自己放在(社区维基?)答案中。 - Georg Fritzsche
半个OT:这不是“初始化”的问题,而是链接的问题。初始化是指在程序成功链接后启动时发生的事情。 - Bahbar
1个回答

5

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


4
Lua 5.1 中没有 -llualib。 - lhf

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接