Lua 5.3未定义的引用 [英] Lua 5.3 undefined references

查看:112
本文介绍了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的未定义参考错误.我正在使用Code ::阻止一台Windows计算机,并且已将lua include目录添加到所有搜索路径,并将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未定义的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆