Sign in to follow this  
Eldritch

Compilation problems with Lua and Luabind

Recommended Posts

I have Lua 5.1 and Luabind 0.7. I am taking the approach of including the Luabind header files in my project instead of building them as a library/DLL, mainly because I cannot for the love of everything holy figure out exactly how to use Boost-Build to actually build Luabind into something usable. Anyways, I am using the following code for my application:
/*
	Main.cpp
*/
extern "C"
{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}

#include <iostream>
#include <luabind/config.hpp>
#include <luabind/class.hpp>
#include <luabind/function.hpp>
#include <luabind/open.hpp>

void greet()
{
	std::cout << "Hello World!\n";
}

void main()
{
	// Initialize Lua and load default libraries.
	lua_State* L = lua_open();
	luaL_openlibs(L);

	// Initialize Luabind.
	luabind::open(L);

	// Initialize a Luabind module.
	luabind::module(L)
	[
		luabind::def("Greet", &greet)
	];
	
	// Close down Lua.
	if (L)
	{
		lua_close(L);
		L = NULL;
	}
}

When I compile, I get a massive amount of errors that look like this:
Compiling...
Main.cpp
c:\program files\microsoft visual studio 8\vc\include\xutility(2282) : warning C4996: 'std::_Copy_opt' was declared deprecated
        c:\program files\microsoft visual studio 8\vc\include\xutility(2270) : see declaration of 'std::_Copy_opt'
        Message: 'You have used a std:: construct that is not safe. See documentation on how to use the Safe Standard C++ Library'
        c:\documents and settings\luncih-3\my documents\sdks\luabind\luabind\detail\primitives.hpp(68) : see reference to function template instantiation '_OutIt std::copy<const char*,char*>(_InIt,_InIt,_OutIt)' being compiled
        with
        [
            _OutIt=char *,
            _InIt=const char *
        ]
Compiling manifest to resources...
Linking...
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
Main.obj : error LNK2019: unresolved external symbol "public: __thiscall luabind::scope::~scope(void)" (??1scope@luabind@@QAE@XZ) referenced in function __unwindfunclet$_main$0
Main.obj : error LNK2019: unresolved external symbol "public: void __thiscall luabind::module_::operator[](struct luabind::scope)" (??Amodule_@luabind@@QAEXUscope@1@@Z) referenced in function _main
Main.obj : error LNK2019: unresolved external symbol "void __cdecl luabind::open(struct lua_State *)" (?open@luabind@@YAXPAUlua_State@@@Z) referenced in function _main
Main.obj : error LNK2019: unresolved external symbol "public: __thiscall luabind::module_::module_(struct lua_State *,char const *)" (??0module_@luabind@@QAE@PAUlua_State@@PBD@Z) referenced in function "class luabind::module_ __cdecl luabind::module(struct lua_State *,char const *)" (?module@luabind@@YA?AVmodule_@1@PAUlua_State@@PBD@Z)
Main.obj : error LNK2019: unresolved external symbol "public: __thiscall luabind::scope::scope(struct luabind::scope const &)" (??0scope@luabind@@QAE@ABU01@@Z) referenced in function "struct luabind::scope __cdecl luabind::def<void (__cdecl*)(void)>(char const *,void (__cdecl*)(void))" (??$def@P6AXXZ@luabind@@YA?AUscope@0@PBDP6AXXZ@Z)
Main.obj : error LNK2019: unresolved external symbol "public: __thiscall luabind::scope::scope(class std::auto_ptr<struct luabind::detail::registration>)" (??0scope@luabind@@QAE@V?$auto_ptr@Uregistration@detail@luabind@@@std@@@Z) referenced in function "struct luabind::scope __cdecl luabind::def<void (__cdecl*)(void)>(char const *,void (__cdecl*)(void))" (??$def@P6AXXZ@luabind@@YA?AUscope@0@PBDP6AXXZ@Z)
Main.obj : error LNK2019: unresolved external symbol "public: __thiscall luabind::detail::registration::registration(void)" (??0registration@detail@luabind@@QAE@XZ) referenced in function "public: __thiscall luabind::detail::function_commiter<void (__cdecl*)(void),struct luabind::detail::null_type>::function_commiter<void (__cdecl*)(void),struct luabind::detail::null_type>(char const *,void (__cdecl*)(void),struct luabind::detail::null_type const &)" (??0?$function_commiter@P6AXXZUnull_type@detail@luabind@@@detail@luabind@@QAE@PBDP6AXXZABUnull_type@12@@Z)
Main.obj : error LNK2019: unresolved external symbol "public: void __thiscall luabind::detail::free_functions::function_rep::add_overload(struct luabind::detail::free_functions::overload_rep const &)" (?add_overload@function_rep@free_functions@detail@luabind@@QAEXABUoverload_rep@234@@Z) referenced in function "public: virtual void __thiscall luabind::detail::function_commiter<void (__cdecl*)(void),struct luabind::detail::null_type>::register_(struct lua_State *)const " (?register_@?$function_commiter@P6AXXZUnull_type@detail@luabind@@@detail@luabind@@UBEXPAUlua_State@@@Z)
Main.obj : error LNK2019: unresolved external symbol "int __cdecl luabind::detail::free_functions::function_dispatcher(struct lua_State *)" (?function_dispatcher@free_functions@detail@luabind@@YAHPAUlua_State@@@Z) referenced in function "public: virtual void __thiscall luabind::detail::function_commiter<void (__cdecl*)(void),struct luabind::detail::null_type>::register_(struct lua_State *)const " (?register_@?$function_commiter@P6AXXZUnull_type@detail@luabind@@@detail@luabind@@UBEXPAUlua_State@@@Z)
Main.obj : error LNK2019: unresolved external symbol "public: static struct luabind::detail::class_registry * __cdecl luabind::detail::class_registry::get_registry(struct lua_State *)" (?get_registry@class_registry@detail@luabind@@SAPAU123@PAUlua_State@@@Z) referenced in function "public: virtual void __thiscall luabind::detail::function_commiter<void (__cdecl*)(void),struct luabind::detail::null_type>::register_(struct lua_State *)const " (?register_@?$function_commiter@P6AXXZUnull_type@detail@luabind@@@detail@luabind@@UBEXPAUlua_State@@@Z)
Main.obj : error LNK2019: unresolved external symbol "int __cdecl luabind::detail::ref(struct lua_State *)" (?ref@detail@luabind@@YAHPAUlua_State@@@Z) referenced in function "public: virtual void __thiscall luabind::detail::function_commiter<void (__cdecl*)(void),struct luabind::detail::null_type>::register_(struct lua_State *)const " (?register_@?$function_commiter@P6AXXZUnull_type@detail@luabind@@@detail@luabind@@UBEXPAUlua_State@@@Z)
Main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall luabind::detail::registration::~registration(void)" (??1registration@detail@luabind@@UAE@XZ) referenced in function "public: virtual __thiscall luabind::detail::function_commiter<void (__cdecl*)(void),struct luabind::detail::null_type>::~function_commiter<void (__cdecl*)(void),struct luabind::detail::null_type>(void)" (??1?$function_commiter@P6AXXZUnull_type@detail@luabind@@@detail@luabind@@UAE@XZ)
C:\Documents and Settings\luncih-3\My Documents\Visual Studio 2005\Projects\LuaTest\Debug\LuaTest.exe : fatal error LNK1120: 12 unresolved externals
Build log was saved at "file://c:\Documents and Settings\luncih-3\My Documents\Visual Studio 2005\Projects\LuaTest\LuaTest\Debug\BuildLog.htm"
LuaTest - 13 error(s), 2 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

What have I missed? I tried looking at the official Luabind guide, some Ogre3D guide and a couple of other (and very similar) guides, but they reveal nothing that I could have missed, except the part where they say it is optional to build Luabind with Boost-Build.

Share this post


Link to post
Share on other sites
Once I figured it out, I had no issues getting Lua/Luabind to work. I did it using Lua 5.0 and the lastest build of luabind on their site (not off the CVS server). I built them using Static Libraries.


My guess with your problem however is that it appears to be unable to find some functions. Are you added all the other non-header files (ie. the ones in the source directory?)properly into your build? Thats where I would start first, but I am no expert.


tHom

Share this post


Link to post
Share on other sites
Luabind 0.7b is not compatible with Lua 5.1+. If you want to use Lua 5.1+, then you must get the HEAD revision of Luabind from CVS. If you don't want to bother getting the HEAD of CVS, then you will have to revert back to using Lua 5.0.x until they release a new build of Luabind.

Share this post


Link to post
Share on other sites
@tHomahwk:

I have added the source files to the project directly, yes. How did you "build them using Static Libraries" ? I am guessing with Boost.Build, but I have no idea how that works considering there is no executable file...

Share this post


Link to post
Share on other sites
I used VS 2005 (Express) and to build it you do this:

1) File -> New Proj -> Win32
2) Select "Win32 Console Application" (obviously select a location/name)
3) Hit "OK"
4) Press "Next" at the bottom on the next window that pops up
5) Then there will be a set of radio buttons, "Window app", "Console App", "DLL", and (the one you want) "Static Library".
6) Turn off precompiled headers, as lua and luabind don't use them.
7) hit ok.
8) add all of the src files for lua (following the directions for lua including with the package you have. It should tell you what files for the core lua interface, and all the libraries). I used a separate library for the following 3 items: Core Lua, Lua Libraries, and Lua Bind (just repeat steps 1 through 9 for each of them)
9) Make sure the path to the header files is included in the project (on the menu,
go "Project" -> "Properties" -> "Configuration Properties" -> C/C++ -> "General" and set the path there).


Once it is done.

Compile (I use the post build step to copy BOTH the .lib and the .pdb files [for debugging] ) to a directory where my project can access it [usually something like "Lua\lib"] ).

Then in your other project, just include it as you would a .lib file "Project" -> "Properties" -> "Configuration Properties" -> "C/C++" -> "Linker" -> "Input" -> "Additional Dependencies" (add the .libs here) and up one in the "General" (under "Linker") -> "Additional Library Directories" -> add the path to those libs

phew that was a mouth full.

if your not using MSVC 2003/2005, can't say I can help you there :(

Share this post


Link to post
Share on other sites
Made all the steps and started compiling... got a really iffy error:


Compiling...
wrapper_base.cpp
c:\program files\microsoft visual studio 8\vc\include\xutility(2282) : warning C4996: 'std::_Copy_opt' was declared deprecated
c:\program files\microsoft visual studio 8\vc\include\xutility(2270) : see declaration of 'std::_Copy_opt'
Message: 'You have used a std:: construct that is not safe. See documentation on how to use the Safe Standard C++ Library'
c:\documents and settings\luncih-3\my documents\sdks\luabind\luabind\detail\primitives.hpp(68) : see reference to function template instantiation '_OutIt std::copy<const char*,char*>(_InIt,_InIt,_OutIt)' being compiled
with
[
_OutIt=char *,
_InIt=const char *
]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this