如何解决 LNK2005: 已定义
我正在开发一个使用 Lua 和 Luabind to C++ 的项目。现在,在我想要导出到 C++ 的每个类中,我编写一个静态方法 Register,如下所示:
在 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)" (??1class_base@detail@luabind@@QAE@XZ) 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 *))" (??0function_object@detail@luabind@@QAE@P6AHPAUlua_State@@@Z@Z) already defined in Button.obj
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: virtual __thiscall luabind::detail::function_object::~function_object(void)" (??1function_object@detail@luabind@@UAE@XZ) already defined in Button.obj
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: __thiscall luabind::detail::invoke_context::operator bool(void)const " (??Binvoke_context@detail@luabind@@QBE_NXZ) already defined in Button.obj
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: __thiscall luabind::detail::invoke_context::invoke_context(void)" (??0invoke_context@detail@luabind@@QAE@XZ) 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 *)" (?set_instance@object_rep@detail@luabind@@QAEXPAVinstance_holder@23@@Z) already defined in Button.obj
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: void * __thiscall luabind::detail::object_rep::allocate(unsigned int)" (?allocate@object_rep@detail@luabind@@QAEPAXI@Z) 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)" (?crep@object_rep@detail@luabind@@QAEPAVclass_rep@23@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 " (?casts@class_rep@detail@luabind@@QBEABVcast_graph@23@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
有人有任何想法吗?
I'm working on a project with Lua and Luabind to C++. Now, in every class I want to export to C++, I write a static method Register like this:
In Button.h:
static luabind::scope Register();
In Button.cpp:
luabind::scope falcon::Button::Register()
{
return
luabind::class_<Button, Button*>("Button")
.def(luabind::constructor<float, float, float, float>());
}
For every class I already exported to Lua, this works fine. But for Button.cpp, this doesn't seem to work.
I get the following linker error:
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: __thiscall luabind::detail::class_base::~class_base(void)" (??1class_base@detail@luabind@@QAE@XZ) 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 *))" (??0function_object@detail@luabind@@QAE@P6AHPAUlua_State@@@Z@Z) already defined in Button.obj
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: virtual __thiscall luabind::detail::function_object::~function_object(void)" (??1function_object@detail@luabind@@UAE@XZ) already defined in Button.obj
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: __thiscall luabind::detail::invoke_context::operator bool(void)const " (??Binvoke_context@detail@luabind@@QBE_NXZ) already defined in Button.obj
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: __thiscall luabind::detail::invoke_context::invoke_context(void)" (??0invoke_context@detail@luabind@@QAE@XZ) 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 *)" (?set_instance@object_rep@detail@luabind@@QAEXPAVinstance_holder@23@@Z) already defined in Button.obj
1>luabindd.lib(luabindd.dll) : error LNK2005: "public: void * __thiscall luabind::detail::object_rep::allocate(unsigned int)" (?allocate@object_rep@detail@luabind@@QAEPAXI@Z) 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)" (?crep@object_rep@detail@luabind@@QAEPAVclass_rep@23@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 " (?casts@class_rep@detail@luabind@@QBEABVcast_graph@23@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
Anyone got any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚通过定义 & 解决了该错误在头文件中声明函数...也许任何人都可以向我解释为什么必须为此类而不是为我想用 Lua 注册的其他 10 个类执行此操作?!
这有点奇怪,因为我在 .cpp 中的其他类中实现了该函数...
I just solved the error by defining & declaring the function in the headerfile... Perhaps anyone can explain this to me why this has to be done for this class and not for, let's say, the 10 other ones I want to register with Lua?!
It's kind of weird, because I implement the function in those other classes in the .cpp...