LUA 编译错误与 Visual 2010“外部符号"struct lua_State * __cdecl luaL_newstate(void)" [英] LUA compile error with Visual 2010 "external symbol "struct lua_State * __cdecl luaL_newstate(void)"
问题描述
我在 Visual Studio 2010 中使用 Lua ver 5.2.3,当我编译下面的代码时
I use Lua ver 5.2.3 with visual studio 2010 , when i compile code below
#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
你能就此给我任何建议吗?谢谢!!!
Could you please give me any advice about this . Thank !!!
推荐答案
这是 C++名称修改"的结果.看看这个词怎么会有奇怪的字符:
This is a result of C++ "name mangling". See how there are strange characters in this term:
?luaL_newstate@@YAPAUlua_State@@XZ
你有选择:
将此文件的文件扩展名更改为 .c 而不是 .cpp,以便它通过 C 编译器而不是 C++ 编译器运行(注意:取决于编译器)
Change the file extension of this file to .c instead of .cpp, so that it runs through the C compiler instead of the C++ compiler (caveat: depending on compiler)
或
在包含的周围添加 extern "C",如下所示:
Add extern "C" around the includes like this:
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
或
#include "lua.hpp"
在最后一种情况下,该头文件包含在 5.2 版本中.它执行我在选项 2 中为您编写的内容.
In the last case, that header is included with the 5.2 release. It does what I wrote in option 2 for you.
这篇关于LUA 编译错误与 Visual 2010“外部符号"struct lua_State * __cdecl luaL_newstate(void)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!