C ++ Lua 5.1问题 [英] C++ Lua 5.1 Issue

查看:202
本文介绍了C ++ Lua 5.1问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
#include <string.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

    int main (void) {
      char buff[256];
      int error;
      lua_State *L = lua_open();   /* opens Lua */
      luaL_openlibs(L);

      while (fgets(buff, sizeof(buff), stdin) != NULL) {
        error = luaL_loadbuffer(L, buff, strlen(buff), "line") ||
                lua_pcall(L, 0, 0, 0);
        if (error) {
          fprintf(stderr, "%s", lua_tostring(L, -1));
          lua_pop(L, 1);  /* pop error message from the stack */
        }
      }

      lua_close(L);
      return 0;
    }

这似乎传播了几个错误,例如:

This seems to propagate several errors such as:

错误LNK2019:在函数_main main中引用的未解析的外部符号char const * __cdecl lua_tolstring(struct lua_State *,int,unsigned int *)(?lua_tolstring @@ YAPBDPAUlua_State @@ HPAI @ Z)。 obj

error LNK2019: unresolved external symbol "char const * __cdecl lua_tolstring(struct lua_State *,int,unsigned int *)" (?lua_tolstring@@YAPBDPAUlua_State@@HPAI@Z) referenced in function _main main.obj

有什么问题?

推荐答案

externC中的头文件以获得正确的符号链接,以及链接到lib(如果你没有编译到项目中)

You need to wrap the lua headers in extern "C" to get the correct symbol linkages, as well as linking to the lib(if your not compiling it into the project)

这篇关于C ++ Lua 5.1问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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