Lua 5.3 未定义引用

Gia*_*e47 4 c++ lua

我正在尝试学习如何将 lua 嵌入到 C 程序中,但我不擅长阅读技术文档,而且我还没有找到任何当前的教程。这是我的程序:

#include <iostream>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>


void report_errors(lua_State*, int);

int main(int argc, char** argv) {
    for (int n = 1; n < argc; ++n) {
        const char* file = argv[n];
        lua_State *L = luaL_newstate();

        luaL_openlibs(L);

        std::cerr << "-- Loading File: " << file << std::endl;

        int s = luaL_loadfile(L, file);

        if (s == 0) {
            s = lua_pcall(L, 0, LUA_MULTRET, 0);
        }

        report_errors(L, s);
        lua_close(L);
        std::cerr << std::endl;
    }
    return 0;
}

void report_errors(lua_State *L, int status) {
    if (status) {
        std::cerr << "-- " << lua_tostring(L, -1) << std::endl;
        lua_pop(L, 1);
    }
}
Run Code Online (Sandbox Code Playgroud)

编译器为 luaL_newstate、luaL_openlibs、luaL_loadfilex、lua_pcallk 和 lua_close 提供未定义的引用错误。我在 Windows 计算机上使用 Code::Blocks one,并且已将 lua 包含目录添加到所有搜索路径,并将 liblua53.a 添加到链接库。IDE 自动完成头名称,解析器显示大部分 lua 函数,但通过简短的搜索,我发现解析器找不到 lua_newstate 或 luaL_newstate。为什么它会找到某些功能而不是其他功能?

FDi*_*off 5

在 C++ 中,你应该包括lua.hppnot lua.hlua.h没有定义extern "C"阻止 C++ 编译器名称修改的块。