Lua 5.3 undefined references(Lua 5.3 未定义的引用)
问题描述
我正在尝试学习如何将 lua 嵌入到 C 程序中,但我不擅长阅读技术文档,而且我还没有找到任何当前的教程.这是我的程序:
I am trying to learn how to embed lua in a C program, but I am not great at reading technical documents, and I haven't found any current tutorials. This is my program:
#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 的未定义引用错误.我在 Windows 计算机上使用 Code::Blocks one,并且已将 lua 包含目录添加到所有搜索路径,并将 liblua53.a 添加到链接库.IDE 自动完成头名称,解析器显示大部分 lua 函数,但通过简短的搜索,我发现解析器找不到 lua_newstate 或 luaL_newstate.为什么它会找到某些功能而不是其他功能?
The compiler gives undefined reference errors for luaL_newstate, luaL_openlibs, luaL_loadfilex, lua_pcallk, and lua_close. I am using Code::Blocks one a Windows computer and I have added the lua include directory to all of the search paths and liblua53.a to the link libraries. The IDE autocompleted the header names and the parser displays most of the lua functions, but with a brief search I found that the parser could not find either lua_newstate or luaL_newstate. Why does it find some of the functions and not others?
推荐答案
g++ 的参数在输入文件之前有 -llua.我把 -llua 放在最后,现在一切正常.
The arguments for g++ had -llua before the input file. I put -llua at the end, and everything works fine now.
这篇关于Lua 5.3 未定义的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Lua 5.3 未定义的引用
基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
