• 11
• 9
• 10
• 9
• 11

# Lua, VC8express and LNK2005

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

## Recommended Posts

So, I'm migrating to Lua for the first time (be gentle!) I'm slapping together a framework with Lua, SDL, and OpenGL using VC8express. The linker complains about a few things being multiply defined in Lua libraries and MSVC libs. I could turn on the nodefaultlibs option, but I'm using std classes pretty extensively. Is there any way to resolve this that wouldn't require suppressing each library individually? Thanks in advance, (P.S. I would prefer solutions that are apparent in-code, like the #pragma comment(lib, "libname.lib") way of linking to libraries. I don't like compiler options as much, because I never remember where anything is in all of those lists! [grin]) [Edited by - templewulf on April 5, 2006 8:39:03 AM]

##### Share on other sites
Well, I guess it's time for a shameless bump.

I decided to drop the static lib in favor of the dll, but I'm still having trouble linking Lua libraries into my C++ app. I have errors as follows:
WulfLua.obj : error LNK2001: unresolved external symbol _luaL_newstateWulfLua.obj : error LNK2001: unresolved external symbol _luaopen_mathWulfLua.obj : error LNK2001: unresolved external symbol _luaopen_stringWulfLua.obj : error LNK2001: unresolved external symbol _luaopen_baseWulfLua.obj : error LNK2001: unresolved external symbol _lua_closeWulfLua.obj : error LNK2001: unresolved external symbol _luaopen_ioWulfLua.obj : error LNK2001: unresolved external symbol _luaopen_packageWulfLua.obj : error LNK2001: unresolved external symbol _luaopen_tableC:\Files\Hobby\Wulf\\bin\Wulf.exe : fatal error LNK1120: 8 unresolved externals
Those are the only lua functions I've used so far, so I'm sure I'm linking something the wrong way, but I haven't found it yet.

I have included lua.hpp, the lua5.1.dll is in the binary output directory, and code generation is MD.

I'm sure I'll slap myself in the head when somebody explains this to me, but don't let that hold you back!

##### Share on other sites
aren't you supposed to wrap some functions or headers with
extern "C"
if you're using C++ with Lua?

##### Share on other sites
Normally, you're right, but I'm using the <lua.hpp> header, which has that in there for you. I don't know when they added it, but it's in the 5.1 release that I just downloaded.

That was a good guess, though. [smile]

Edit:
I have to get to sleep for work tomorrow. If anybody has an idea overnight, I'd really appreciate it! Thanks, everybody (who might read this).

##### Share on other sites
Well, you didn't mention adding the import library for the Lua 5.1 DLL. You still need a .lib for linking to DLLs. Also, if you still want help with the static version, post the list of errors you get from linking to it.

##### Share on other sites
Well, I didn't know you still had to link the static libraries! Now it works fine!

Although, in my earlier attempt to use the static library as a standalone, it told me that functions in Lua.5.1.lib were already defined in MSVC lib such-and-such.

You guys are great; Ratings++ all around! [smile]