Embedding Lua in Visual C++ 2008
Moderator: PC Supremacists
Embedding Lua in Visual C++ 2008
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."
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."
Last edited by Cole S. on Sun Dec 07, 2008 9:56 am, edited 1 time in total.
Personal Youtube: http://www.youtube.com/user/xXShadowAsasNXx
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Embedding Lua in Visual C++ 2008
Did you add -lualib5.1 or whatever your .lib is named to your link line?
Re: Embedding Lua in Visual C++ 2008
What do you mean Link Line...
Personal Youtube: http://www.youtube.com/user/xXShadowAsasNXx
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
Re: Embedding Lua in Visual C++ 2008
Nvm stupid question... but how would i add it... thorugh the project properties or global settings?
Personal Youtube: http://www.youtube.com/user/xXShadowAsasNXx
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
Re: Embedding Lua in Visual C++ 2008
Wait... I don't have .lib files i have .obj files?????
Personal Youtube: http://www.youtube.com/user/xXShadowAsasNXx
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
- cypher1554R
- Chaos Rift Demigod
- Posts: 1124
- Joined: Sun Jun 22, 2008 5:06 pm
Re: Embedding Lua in Visual C++ 2008
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)
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)
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Embedding Lua in Visual C++ 2008
Just compile the .c and .h files into your own library and link against it.
Re: Embedding Lua in Visual C++ 2008
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?GyroVorbis wrote:Did you add -lualib5.1 or whatever your .lib is named to your link line?
- cypher1554R
- Chaos Rift Demigod
- Posts: 1124
- Joined: Sun Jun 22, 2008 5:06 pm
Re: Embedding Lua in Visual C++ 2008
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..Fear wrote: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?GyroVorbis wrote:Did you add -lualib5.1 or whatever your .lib is named to your link line?
Re: Embedding Lua in Visual C++ 2008
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???
Personal Youtube: http://www.youtube.com/user/xXShadowAsasNXx
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
Re: Embedding Lua in Visual C++ 2008
Yes, i moved it to the compiler directory and the error doesn't go awaycypher1554R wrote: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..Fear wrote: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?GyroVorbis wrote:Did you add -lualib5.1 or whatever your .lib is named to your link line?
Re: Embedding Lua in Visual C++ 2008
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??
Personal Youtube: http://www.youtube.com/user/xXShadowAsasNXx
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
Re: Embedding Lua in Visual C++ 2008
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.
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.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
Re: Embedding Lua in Visual C++ 2008
Where is the project root??
Personal Youtube: http://www.youtube.com/user/xXShadowAsasNXx
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
Prelimse Studios Youtube: http://www.youtube.com/user/PrelimseStudios
Prelimse Studios Website: http://www.prelimsestudios.com/
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Embedding Lua in Visual C++ 2008
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).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???