Skip to main content
gamedev.net
🔒 Locked

Lua Linking Errors

Started by Zortacus Aug 26, 2008 at 6:13 AM 5 replies 1.4k views
Original Post
Zortacus
Zortacus
Hi, I'm aware how silly this is, but I can't get Lua to link with my project. I am using MSVC++ 2008 Express Edition. I have created a new console application, and added a message. It compiles, and runs. I then downloaded the binary x86 static library and includes package for Visual C++ 2008. After copying these files to appropriate places inside my project directory, I modified the project settings for both configurations so that /lua/include is listed under "Additional Include Directories", /lua/libs is listed under "Additional Library Directories" and "Additional Dependencies" now contains lua5.1.lib. The main (and only) source file now reads:

extern "C"
{
	#include "lua.h"
	#include "lualib.h"
	#include "lauxlib.h"
}

int main( int argc, const char *argv[] )
{
	lua_State *L = lua_open();
	lua_close( L );
}

I get no compile errors, but no such luck with linking.
Quote:
1>main.obj : error LNK2019: unresolved external symbol _lua_close referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol _luaL_newstate referenced in function _main
I've been searching through the google results for these errors for the past few hours, which is pretty hopeless. I really can't figure out what I'm doing wrong. Can anyone point me in the right direction? Thanks so much.
BigJim
BigJim
Have you tried choosing a different 'Runtime library' setting under the 'Code Generation' settings for your project, I find you often need to change this to persuade VC to link to 3rd party libraries..
ddn3
ddn3
If you've included Lua in anohter project in your solution and your game code isn't in the same project as Lua, but its own, then you will also need to tell VStudio to explcitly link with that project. Todo this you will need too go through the menu Project->Project Dependices, select your main project and it will list the other projects with a check box next too them. Check all the other projects which your main project depends on, in this case the Lua project.

That will cause VStudio to link and build that project when you rebuild your main project.

Good Luck!

-ddn
Zortacus
Zortacus
Thanks for the suggestions. I tried playing around with the run-time library types, no joy.

As far as project dependencies, I am trying to get a minimal working example, so there is only one project in the solution (and I am trying to link to a ready made Lua binary, not make one myself).

Any other ideas? :(
ddn3
ddn3
You're doing everything correctly as far as I can tell, including it in the project properties and giving it the lib path should atleast allow you to link it. I would suggest download the Lua src and make it a project you include with your solution, that's the best and easiest way I've found. For now you can just drop the Lua src right into your sole project and it would work just as well.

Good Luck!

-ddn
Zortacus
Zortacus
Yeah, I have no idea why either, so I'll give that a go.

Thanks
Scourage
Scourage
Are you defining the preprocessor define "LUA_BUILD_AS_DLL"? You may need it defined so that the functions are defined as dllimport.

edit: I just saw that you're using a static library. This probably won't help. sorry

Cheers,

Bob

[size="3"]Halfway down the trail to Hell...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.