首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何求解LNK2005:已定义

如何求解LNK2005:已定义
EN

Stack Overflow用户
提问于 2011-12-19 23:57:52
回答 1查看 1.4K关注 0票数 0

我正在与Lua和Luabind to C++合作一个项目。现在,在我想要导出到C++的每个类中,我编写了一个静态方法Register,如下所示:

在Button.h中:

代码语言:javascript
复制
static luabind::scope Register();

在Button.cpp中:

代码语言:javascript
复制
luabind::scope falcon::Button::Register()
{
    return 
        luabind::class_<Button, Button*>("Button")
        .def(luabind::constructor<float, float, float, float>());
}

对于我已经导出到Lua的每个类,这都可以很好地工作。但对于Button.cpp来说,这似乎行不通。

我得到以下链接器错误:

代码语言:javascript
复制
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

有人有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-20 18:18:26

我只是通过在headerfile中定义和声明函数来解决这个错误...也许任何人都可以向我解释为什么必须为这个类这样做,而不是为我想要注册到Lua的其他10个类?!

这有点奇怪,因为我在.cpp的其他类中实现了这个函数……

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8563903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档