Lua 5.3 未定义的引用
Lua 5.3 undefined references
我正在尝试学习如何将 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);
}
}
编译器为 luaL_newstate、luaL_openlibs、luaL_loadfilex、lua_pcallk 和 lua_close 给出了未定义的引用错误。我正在使用 Code::Blocks 一台 Windows 计算机,我已将 lua 包含目录添加到所有搜索路径,并将 liblua53.a 添加到 link 库。 IDE 自动完成了 header 名称,解析器显示了大多数 lua 函数,但通过简短搜索,我发现解析器找不到 lua_newstate 或 luaL_newstate。为什么它找到了一些功能而不是其他功能?
在 C++ 中,您应该包含 lua.hpp
而不是 lua.h
。 lua.h
没有定义 extern "C"
块来阻止 c++ 编译器的名称重整。
g++ 的参数在输入文件之前有 -llua。我把 -llua 放在最后,现在一切正常。
我正在尝试学习如何将 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);
}
}
编译器为 luaL_newstate、luaL_openlibs、luaL_loadfilex、lua_pcallk 和 lua_close 给出了未定义的引用错误。我正在使用 Code::Blocks 一台 Windows 计算机,我已将 lua 包含目录添加到所有搜索路径,并将 liblua53.a 添加到 link 库。 IDE 自动完成了 header 名称,解析器显示了大多数 lua 函数,但通过简短搜索,我发现解析器找不到 lua_newstate 或 luaL_newstate。为什么它找到了一些功能而不是其他功能?
在 C++ 中,您应该包含 lua.hpp
而不是 lua.h
。 lua.h
没有定义 extern "C"
块来阻止 c++ 编译器的名称重整。
g++ 的参数在输入文件之前有 -llua。我把 -llua 放在最后,现在一切正常。