2011-12-19 69 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中執行那些其他類中的函數...

相關問題