LUA 编译错误与 Visual 2010"外部符号"结构lua_State * __cdecl luaL_newstate(无效)"

LUA compile error with Visual 2010 "external symbol "struct lua_State * __cdecl luaL_newstate(void)"

本文关键字:cdecl State newstate 无效 luaL 结构 错误 编译 Visual 2010 LUA      更新时间:2023-10-16

当我编译下面的代码时,我将Lua ver 5.2.3与Visual Studio 2010一起使用

#include "stdafx.h"
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include <stdlib.h>                          
#include <stdio.h> 
void main()
{
    lua_State *luaState = luaL_newstate();
}

我收到错误

error LNK2019: unresolved external symbol "struct lua_State * __cdecl luaL_newstate(void)" (?luaL_newstate@@YAPAUlua_State@@XZ) referenced in function _wmain

你能给我任何建议吗?谢谢!!!

这是

C++"名称重整"的结果。 看看这个术语中是如何有奇怪的字符的:

?luaL_newstate@@YAPAUlua_State@@XZ

您可以选择:

将此文件的文件扩展名更改为 .c 而不是 .cpp,以便它通过 C 编译器而不是C++编译器运行(警告:取决于编译器)

在包含周围添加外部"C",如下所示:

extern "C"
{
    #include "lua.h"
    #include "lauxlib.h"
    #include "lualib.h"
}

#include "lua.hpp"

在最后一种情况下,该标头包含在 5.2 版本中。它为您执行我在选项 2 中编写的内容。