# ARRGH! Problems linking Lua 5.1

This topic is 4174 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Well, okay. I'm trying to integrate Lua just like everyone else, and am getting linker errors for, essentially, every lua_* function. I'm linking to the library produced by the MSVC (7.1) build script included with the source; the following code generates the following errors:
#include <lua\lua.h>
#include <lua\lauxlib.h>

#pragma comment ( lib, "lua51.lib" )

int main(int argc, char* argv[])
{
lua_State* L = luaL_newstate();

lua_close(L);
return 0;
}

// error LNK2019: unresolved external symbol "void __cdecl lua_close(struct lua_State *)"
// error LNK2019: unresolved external symbol "struct lua_State * __cdecl luaL_newstate(void)"


The libs were built using the luavs.bat script included with the Lua source. Ideas?

##### Share on other sites
Is this C or C++ code? if the latter you want to prevent name mangling by
Quote:
 extern "C"{# include "lua.h"# include "lauxlib.h"# include "lualib.h"}

Quote:
 C++ compilation has 3 distinct steps

Very true :)

##### Share on other sites
Quote:
 Original post by dmailfirstly you want to link the lib before including the headers.

Inconsequential - C++ compilation has 3 distinct steps (preprocessing, compilation, linking) during which the #include and #pragma directives (in this case) are processed in such a way that their order is irrelevant.
Quote:
 Is this C or C++ code? if the latter you want to prevent name mangling by

C++. Lemmie give that a shot, seems like that's a more probable issue.

EDIT: Yep, that was it. Big thanks <3 <3