2011-12-19 86 views
0

我正在与Lua和Luabind合作开发一个项目到C++。现在,在每堂课我想出口到C++,我写了一个静态方法注册这样的:我该如何解决LNK2005:已经定义

在Button.h:

static luabind::scope Register(); 

在Button.cpp:

luabind::scope falcon::Button::Register() 
{ 
    return 
     luabind::class_<Button, Button*>("Button") 
     .def(luabind::constructor<float, float, float, float>()); 
} 

对于我已经输出到Lua的每个班级,这工作正常。但对于Button.cpp,这似乎不起作用。

我得到下面的连接错误:

1>luabindd.lib(luabindd.dll) : error LNK2005: "public: __thiscall luabind::detail::class_base::~class_base(void)" ([email protected]@[email protected]@[email protected]) already defined in Button.obj 
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: __thiscall luabind::detail::function_object::function_object(int (__cdecl*)(struct lua_State *))" ([email protected]@[email protected]@[email protected][email protected]@@[email protected]) already defined in Button.obj 
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: virtual __thiscall luabind::detail::function_object::~function_object(void)" ([email protected]@[email protected]@[email protected]) already defined in Button.obj 
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: __thiscall luabind::detail::invoke_context::operator bool(void)const " ([email protected]@[email protected]@QBE_NXZ) already defined in Button.obj 
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: __thiscall luabind::detail::invoke_context::invoke_context(void)" ([email protected]@[email protected]@[email protected]) already defined in Button.obj 
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: void __thiscall luabind::detail::object_rep::set_instance(class luabind::detail::instance_holder *)" ([email protected][email protected]@[email protected]@[email protected]@@Z) already defined in Button.obj 
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: void * __thiscall luabind::detail::object_rep::allocate(unsigned int)" ([email protected][email protected]@[email protected]@[email protected]) already defined in Button.obj 
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: class luabind::detail::class_rep * __thiscall luabind::detail::object_rep::crep(void)" ([email protected][email protected]@[email protected]@[email protected]@XZ) already defined in Button.obj 
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: class luabind::detail::cast_graph const & __thiscall luabind::detail::class_rep::casts(void)const " ([email protected][email protected]@[email protected]@[email protected]@XZ) already defined in Button.obj 
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library 
1>D:\Users\THijs\Dropbox\3DAE\Platform Development\Falcon Engine\main\FalconEngine\Debug\FalconEngine.exe : fatal error LNK1169: one or more multiply defined symbols found 

任何人有什么想法?

+0

问题不在于显示的静态函数。不知何故,你将重复的命名外部函数定义放入包含Button的翻译单元中。您需要发布更多代码或手动查看该TU中的包含文件 – sehe 2011-12-19 16:14:12

+0

您是否希望我将所有代码发布到我的Button类中? – ThijsM 2011-12-19 16:20:59

+0

我希望你把焦点转移到问题的根源:)你如何表达它,我不知道,因为我没有你的代码... – sehe 2011-12-19 16:22:20

回答

0

我刚刚通过定义&在头文件中声明函数来解决错误......也许任何人都可以向我解释这是为什么要为这个类而做,而不是为了让我们说,我想要的其他10个注册Lua ?!

这有点奇怪,因为我在.cpp中执行那些其他类中的函数...

相关问题