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();
}
I got error
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 !!!
This is a result of C++ "name mangling". See how there are strange characters in this term:
?luaL_newstate@@YAPAUlua_State@@XZ
You have choices:
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)
or
Add extern "C" around the includes like this:
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
or
#include "lua.hpp"
In the last case, that header is included with the 5.2 release. It does what I wrote in option 2 for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.