Page 1 of 2

Embedding Lua in Visual C++ 2008

Posted: Sat Dec 06, 2008 9:18 pm
by Cole S.
Well, I am making a game engine for Windows with C++, Win32 API, DirectX, and Lua. So far everything has been working fine except for Lua and it's really getting annoying... Anyways, I have downloaded the Lua source code, built it, and i can run any script i put in the lua.exe application (the console app) such as: print("hello"). Here's where my problem is, I have added the src folder in the MSVC++ include directories, and in the library directories. When I try to compile this program:

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

int main()
{

lua_State *L = lua_open();

// load the libs
luaL_openlibs(L);

printf("Hello World");

lua_close(L);

return 0;
}

I get the following build log...

1>------ Build started: Project: luatest, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>Linking...
1>main.obj : error LNK2019: unresolved external symbol _lua_close referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _luaL_openlibs referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _luaL_newstate referenced in function _main
1>C:\Users\Cole\Documents\Visual Studio 2008\Projects\luatest\Debug\luatest.exe : fatal error LNK1120: 3 unresolved externals
1>Build log was saved at "file://c:\Users\Cole\Documents\Visual Studio 2008\Projects\luatest\luatest\Debug\BuildLog.htm"
1>luatest - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

WHAT THE HECK IS GOING ON!!! I have looked all over the internet and I cannot find what is wrong!!! Please reply soon.

----------------------------------------------------------------------------------------------------------------------------------------------

Edit- I can now compile it but when i try to run it it says "This application has failed to start because lua5.1.4.dll was not found. Re-installing the application may fix this problem."

Re: Embedding Lua in Visual C++ 2008

Posted: Sat Dec 06, 2008 9:49 pm
by Falco Girgis
Did you add -lualib5.1 or whatever your .lib is named to your link line?

Re: Embedding Lua in Visual C++ 2008

Posted: Sat Dec 06, 2008 10:25 pm
by Cole S.
What do you mean Link Line...

Re: Embedding Lua in Visual C++ 2008

Posted: Sat Dec 06, 2008 10:39 pm
by Cole S.
Nvm stupid question... but how would i add it... thorugh the project properties or global settings?

Re: Embedding Lua in Visual C++ 2008

Posted: Sat Dec 06, 2008 10:53 pm
by Cole S.
Wait... I don't have .lib files i have .obj files?????

Re: Embedding Lua in Visual C++ 2008

Posted: Sun Dec 07, 2008 4:19 am
by cypher1554R
Make sure you have the official library package. If you do have it, then check for .cpp or .c files that correspond with your .h files and include them in your project.

If you do find the .lib file then copy/move it to your compiler/platform folder into the "lib" directory. In the solution explorer right click on the project file->Properties->Configuration Properties->Linker->Input, and in the Additional Dependencies write down the lib's name (lualib.lib - for example)

Re: Embedding Lua in Visual C++ 2008

Posted: Sun Dec 07, 2008 5:06 am
by Falco Girgis
Just compile the .c and .h files into your own library and link against it.

Re: Embedding Lua in Visual C++ 2008

Posted: Sun Dec 07, 2008 7:55 am
by Fear
GyroVorbis wrote:Did you add -lualib5.1 or whatever your .lib is named to your link line?
I'm having the same problem of Cole S. and i added -lualib5.1 to the link line and i am still receving the same error. What's wrong?

Re: Embedding Lua in Visual C++ 2008

Posted: Sun Dec 07, 2008 8:30 am
by cypher1554R
Fear wrote:
GyroVorbis wrote:Did you add -lualib5.1 or whatever your .lib is named to your link line?
I'm having the same problem of Cole S. and i added -lualib5.1 to the link line and i am still receving the same error. What's wrong?
Did you move the lualib5.1.lib file to your compiler's lib directory? cause the compiler won't tell you if it's not there..

Re: Embedding Lua in Visual C++ 2008

Posted: Sun Dec 07, 2008 9:13 am
by Cole S.
I have the source package... the one with nothing compiled, and I followed this guide to build it http://media.wiley.com/product_data/exc ... 069171.pdf , and I have .obj files for every c file... so should i just include everything into a project file and compile it like that, or do i have to build it another way to get a .lib file???

Re: Embedding Lua in Visual C++ 2008

Posted: Sun Dec 07, 2008 9:35 am
by Fear
cypher1554R wrote:
Fear wrote:
GyroVorbis wrote:Did you add -lualib5.1 or whatever your .lib is named to your link line?
I'm having the same problem of Cole S. and i added -lualib5.1 to the link line and i am still receving the same error. What's wrong?
Did you move the lualib5.1.lib file to your compiler's lib directory? cause the compiler won't tell you if it's not there..
Yes, i moved it to the compiler directory and the error doesn't go away

Re: Embedding Lua in Visual C++ 2008

Posted: Sun Dec 07, 2008 9:40 am
by Cole S.
Okay I re-built it and found that i had lua5.1.4.lib and lua5.1.4-static the dependency thing worked. It compiles but when i run it it says "This application has failed to start because lua5.1.4.dll was not found. Re-installing the application may fix this problem." But i know my dll is fine... Do i copy it into the project file??

Re: Embedding Lua in Visual C++ 2008

Posted: Sun Dec 07, 2008 10:56 am
by avansc
yeas. or you can put it in System32 folder.

but that could be dagerouse.
just put it in the exe directory.

not that if you compile from vs2008 it does not run the program formt he debug/erlease forder/

you would have to put the dll in the project root. ie, where all the source is. thats where VS executes the program when you run it from the IDE.

Re: Embedding Lua in Visual C++ 2008

Posted: Sun Dec 07, 2008 11:07 am
by Cole S.
Where is the project root??

Re: Embedding Lua in Visual C++ 2008

Posted: Sun Dec 07, 2008 11:12 am
by Falco Girgis
Cole S. wrote:I have the source package... the one with nothing compiled, and I followed this guide to build it http://media.wiley.com/product_data/exc ... 069171.pdf , and I have .obj files for every c file... so should i just include everything into a project file and compile it like that, or do i have to build it another way to get a .lib file???
There's a special project setting called "Static Linked Library" which lets you compile it all to a library. The .o files are for if you were to include it directly into your project (which you shouldn't).