【发布时间】:2013-12-18 22:26:27
【问题描述】:
我尝试使用以下 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_loadfile 和 lua_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。
【问题讨论】:
标签: c++ c compiler-construction linker lua