我正在尝试编译程序,并且遇到了奇怪的错误。我已经在Cocos2d-x中寻找了任何重新定义的方法,但似乎找不到。我只是无所适从,何去何从,这甚至意味着什么。

1>libcocos2d.lib(libcocos2d.dll) : error LNK2005: "public: char const * __thiscall tinyxml2::XMLElement::GetText(void)const " (?GetText@XMLElement@tinyxml2@@QBEPBDXZ) already defined in tinyxml2.obj
1>libcocos2d.lib(libcocos2d.dll) : error LNK2005: "public: enum tinyxml2::XMLError __thiscall tinyxml2::XMLElement::QueryIntText(int *)const " (?QueryIntText@XMLElement@tinyxml2@@QBE?AW4XMLError@2@PAH@Z) already defined in tinyxml2.obj
1>libcocos2d.lib(libcocos2d.dll) : error LNK2005: "public: enum tinyxml2::XMLError __thiscall tinyxml2::XMLElement::QueryFloatText(float *)const " (?QueryFloatText@XMLElement@tinyxml2@@QBE?AW4XMLError@2@PAM@Z) already defined in tinyxml2.obj
1>libcocos2d.lib(libcocos2d.dll) : error LNK2005: "public: __thiscall tinyxml2::XMLDocument::XMLDocument(bool,enum tinyxml2::Whitespace)" (??0XMLDocument@tinyxml2@@QAE@_NW4Whitespace@1@@Z) already defined in tinyxml2.obj
1>libcocos2d.lib(libcocos2d.dll) : error LNK2005: "public: virtual __thiscall tinyxml2::XMLDocument::~XMLDocument(void)" (??1XMLDocument@tinyxml2@@UAE@XZ) already defined in tinyxml2.obj
1>libcocos2d.lib(libcocos2d.dll) : error LNK2005: "public: class tinyxml2::XMLNode * __thiscall tinyxml2::XMLNode::InsertFirstChild(class tinyxml2::XMLNode *)" (?InsertFirstChild@XMLNode@tinyxml2@@QAEPAV12@PAV12@@Z) already defined in tinyxml2.obj
1>libcocos2d.lib(libcocos2d.dll) : error LNK2005: "public: void __thiscall tinyxml2::XMLNode::DeleteChildren(void)" (?DeleteChildren@XMLNode@tinyxml2@@QAEXXZ) already defined in tinyxml2.obj
1>libcocos2d.lib(libcocos2d.dll) : error LNK2005: "public: enum tinyxml2::XMLError __thiscall tinyxml2::XMLDocument::LoadFile(char const *)" (?LoadFile@XMLDocument@tinyxml2@@QAE?AW4XMLError@2@PBD@Z) already defined in tinyxml2.obj
1>libcocos2d.lib(libcocos2d.dll) : error LNK2005: "public: enum tinyxml2::XMLError __thiscall tinyxml2::XMLDocument::SaveFile(char const *,bool)" (?SaveFile@XMLDocument@tinyxml2@@QAE?AW4XMLError@2@PBD_N@Z) already defined in tinyxml2.obj
1>libcocos2d.lib(libcocos2d.dll) : error LNK2005: "public: class tinyxml2::XMLElement * __thiscall tinyxml2::XMLDocument::NewElement(char const *)" (?NewElement@XMLDocument@tinyxml2@@QAEPAVXMLElement@2@PBD@Z) already defined in tinyxml2.obj
1>libcocos2d.lib(libcocos2d.dll) : error LNK2005: "public: class tinyxml2::XMLText * __thiscall tinyxml2::XMLDocument::NewText(char const *)" (?NewText@XMLDocument@tinyxml2@@QAEPAVXMLText@2@PBD@Z) already defined in tinyxml2.obj

最佳答案

Cocos2D-X已经包含TinyXML。该错误表明TinyXML源文件已被编译两次。例如,如果cocos2d-x是一个单独的构建目标,并且您已将TinyXML文件添加到您的应用项目目标,则由于两个库/目标文件中存在相同的符号,因此将发生此错误。

解决方案:不要将TinyXML源文件添加到您的项目中,只需#include cocos2d-x提供的TinyXML header 即可。

10-07 12:51