LUA 编译错误与 Visual 2010“外部符号”struct lua_State * __cdecl luaL_newstate(void)”

led*_*ien 1 c++ lua visual-studio-2010

当我编译下面的代码时,我将 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();

}
Run Code Online (Sandbox Code Playgroud)

我有错误

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

你能不能给我一些关于这方面的建议。谢谢 !!!

010*_*101 5

这是 C++“名称修改”的结果。看看这个词怎么会有奇怪的字符:

?luaL_newstate@@YAPAUlua_State@@XZ
Run Code Online (Sandbox Code Playgroud)

你有选择:

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

或者

在包含的周围添加 extern "C",如下所示:

extern "C"
{
    #include "lua.h"
    #include "lauxlib.h"
    #include "lualib.h"
}
Run Code Online (Sandbox Code Playgroud)

或者

#include "lua.hpp"
Run Code Online (Sandbox Code Playgroud)

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