我有点困惑,我正在尝试开发一个简单的应用程序。
应用程序流程:主窗口 -> 对话框 1 -> 对话框 2。
MainWindow 导入 Dialog1.h 和 Dialog1.h 导入 Dialog2.h
1) 如果我在 Dialog1.cpp 和 Dialog2.cpp 中都导入 TinyXML 库,编译器会抛出以下错误:重复符号 **RANDOM TINYXML CLASS* in: Dialog1.o Dialog2.o
2)当Dialog1.h导入Dialog2.h时,即使我尝试仅在Dialog2.h中导入TinyXML库,我仍然会收到以下错误:重复符号**RANDOM TINYXML CLASS* in:mainwindow.o moc_Dialog2.o
我没有在主窗口中导入任何内容。错误仍然存在。
关于我哪里出错的任何帮助?
错误日志(有732,只是复制粘贴了一堆):
duplicate symbol __ZN11TiXmlString7reserveEm in:
mainwindow.o
selectorteach.o
duplicate symbol __ZN11TiXmlString8nullrep_E in:
mainwindow.o
selectorteach.o
duplicate symbol __ZN11TiXmlString6assignEPKcm in:
mainwindow.o
selectorteach.o
duplicate symbol __ZN11TiXmlString6appendEPKcm in:
mainwindow.o
selectorteach.o
duplicate symbol __ZplRK11TiXmlStringS1_ in:
mainwindow.o
selectorteach.o
duplicate symbol __ZplRK11TiXmlStringPKc in:
mainwindow.o
selectorteach.o
duplicate symbol __ZplPKcRK11TiXmlString in:
mainwindow.o
selectorteach.o
duplicate symbol __Z10TiXmlFOpenPKcS0_ in:
mainwindow.o
selectorteach.o
duplicate symbol __ZN9TiXmlBase12EncodeStringERK11TiXmlStringPS0_ in:
mainwindow.o
selectorteach.o
duplicate symbol __ZN9TiXmlBase6entityE in:
mainwindow.o
selectorteach.o
duplicate symbol __ZN9TiXmlNodeC2ENS_8NodeTypeE in:
mainwindow.o
selectorteach.o
duplicate symbol __ZTV9TiXmlNode in:
mainwindow.o
selectorteach.o
duplicate symbol __ZN9TiXmlNodeD2Ev in:
mainwindow.o
selectorteach.o
duplicate symbol __ZN9TiXmlNodeD1Ev in:
mainwindow.o
selectorteach.o
duplicate symbol __ZN9TiXmlNodeD0Ev in:
mainwindow.o
selectorteach.o
duplicate symbol __ZNK9TiXmlNode6CopyToEPS_ in:
mainwindow.o
selectorteach.o
duplicate symbol __ZN9TiXmlNode5ClearEv in:
mainwindow.o
selectorteach.o
--------------------------------------------------------------------
duplicate symbol __ZNK12TiXmlElement22QueryUnsignedAttributeEPKcPj in:
mainwindow.o
teachmode.o
duplicate symbol __ZNK12TiXmlElement18QueryBoolAttributeEPKcPb in:
mainwindow.o
teachmode.o
duplicate symbol __ZN9TiXmlBase11StringEqualEPKcS1_b13TiXmlEncoding in:
mainwindow.o
teachmode.o
duplicate symbol __ZNK12TiXmlElement20QueryDoubleAttributeEPKcPd in:
mainwindow.o
teachmode.o
duplicate symbol __ZN12TiXmlElement12SetAttributeEPKci in:
mainwindow.o
teachmode.o
duplicate symbol __ZN17TiXmlAttributeSet12FindOrCreateEPKc in:
mainwindow.o
teachmode.o
duplicate symbol __ZN14TiXmlAttribute11SetIntValueEi in:
mainwindow.o
teachmode.o
duplicate symbol __ZN17TiXmlAttributeSet3AddEP14TiXmlAttribute in:
mainwindow.o
teachmode.o
duplicate symbol __ZN12TiXmlElement18SetDoubleAttributeEPKcd in:
mainwindow.o
teachmode.o
duplicate symbol __ZN14TiXmlAttribute14SetDoubleValueEd in:
mainwindow.o
teachmode.o
duplicate symbol __ZNK12TiXmlElement5PrintEP7__sFILEi in:
mainwindow.o
teachmode.o
duplicate symbol __ZNK12TiXmlElement6AcceptEP12TiXmlVisitor in:
mainwindow.o
teachmode.o
duplicate symbol __ZNK12TiXmlElement5CloneEv in:
mainwindow.o
teachmode.o
duplicate symbol __ZNK12TiXmlElement7GetTextEv in:
mainwindow.o
teachmode.o
duplicate symbol __ZN13TiXmlDocumentC2Ev in:
--------------------------------------------------------------------
duplicate symbol __ZN9TiXmlBase6entityE in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN9TiXmlNodeC2ENS_8NodeTypeE in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZTV9TiXmlNode in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN9TiXmlNodeD2Ev in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN9TiXmlNodeD1Ev in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN9TiXmlNodeD0Ev in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZNK9TiXmlNode6CopyToEPS_ in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN9TiXmlNode5ClearEv in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN9TiXmlNode12LinkEndChildEPS_ in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN13TiXmlDocument8SetErrorEiPKcP16TiXmlParsingData13TiXmlEncoding in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZNK9TiXmlNode11GetDocumentEv in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN9TiXmlBase11errorStringE in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN16TiXmlParsingData5StampEPKc13TiXmlEncoding in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN9TiXmlNode14InsertEndChildERKS_ in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN9TiXmlNode17InsertBeforeChildEPS_RKS_ in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN9TiXmlNode16InsertAfterChildEPS_RKS_ in:
mainwindow.o
moc_selectorteach.o
duplicate symbol __ZN9TiXmlNode12ReplaceChildEPS_RKS_ in:
--------------------------------------------------------------------
moc_teachmode.o
duplicate symbol __ZN9TiXmlText5ParseEPKcP16TiXmlParsingData13TiXmlEncoding in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZN16TiXmlDeclaration5ParseEPKcP16TiXmlParsingData13TiXmlEncoding in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTV12TiXmlPrinter in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTV14TiXmlAttribute in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTV12TiXmlUnknown in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTV9TiXmlText in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZN11TiXmlString4nposE in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTI9TiXmlNode in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTI12TiXmlElement in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTI13TiXmlDocument in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTI12TiXmlComment in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTI16TiXmlDeclaration in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTI14TiXmlAttribute in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTS14TiXmlAttribute in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTS9TiXmlNode in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTS12TiXmlComment in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTI9TiXmlText in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTS9TiXmlText in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTS16TiXmlDeclaration in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTI12TiXmlUnknown in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTS12TiXmlUnknown in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTS13TiXmlDocument in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTI12TiXmlPrinter in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTS12TiXmlPrinter in:
mainwindow.o
moc_teachmode.o
duplicate symbol __ZTS12TiXmlElement in:
mainwindow.o
moc_teachmode.o
ld: 732 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [untitled.app/Contents/MacOS/untitled] Error 1
19:03:15: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project untitled (kit: Desktop Qt 5.4.0 clang 64bit)
When executing step "Make"
注意:当我只在 Dialog2.cpp 中包含文件时,项目编译并且所有功能都按预期工作。仅当我将其放在头文件中时才会出现此问题。我的 TinyXML 包含指令:-
#include <tinystr.h>
#include <tinyxml.h>
#include <tinystr.cpp>
#include <tinyxmlerror.cpp
#include <tinyxml.cpp>
#include <tinyxmlparser.cpp>
如果我只包含源文件,例如:
#include <tinystr.h>
#include <tinyxml.h>
我收到以下错误日志:
Undefined symbols for architecture x86_64:
"TiXmlString::assign(char const*, unsigned long)", referenced from:
TiXmlString::operator=(char const*) in teachmode.o
"TiXmlString::nullrep_", referenced from:
TiXmlString::quit() in teachmode.o
"TiXmlElement::SetAttribute(char const*, char const*)", referenced from:
saveData(product) in teachmode.o
"TiXmlElement::SetAttribute(char const*, int)", referenced from:
saveData(product) in teachmode.o
"TiXmlElement::TiXmlElement(char const*)", referenced from:
saveData(product) in teachmode.o
"TiXmlDocument::LoadFile(char const*, TiXmlEncoding)", referenced from:
saveData(product) in teachmode.o
"TiXmlDocument::TiXmlDocument()", referenced from:
saveData(product) in teachmode.o
"TiXmlDeclaration::TiXmlDeclaration(char const*, char const*, char const*)", referenced from:
saveData(product) in teachmode.o
"TiXmlNode::LinkEndChild(TiXmlNode*)", referenced from:
saveData(product) in teachmode.o
"TiXmlNode::TiXmlNode(TiXmlNode::NodeType)", referenced from:
TiXmlText::TiXmlText(char const*) in teachmode.o
"TiXmlNode::~TiXmlNode()", referenced from:
TiXmlDocument::~TiXmlDocument() in teachmode.o
TiXmlText::TiXmlText(char const*) in teachmode.o
"TiXmlDocument::SaveFile(char const*) const", referenced from:
saveData(product) in teachmode.o
"TiXmlNode::FirstChildElement() const", referenced from:
TiXmlNode::FirstChildElement() in teachmode.o
"vtable for TiXmlDocument", referenced from:
TiXmlDocument::~TiXmlDocument() in teachmode.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for TiXmlText", referenced from:
TiXmlText::TiXmlText(char const*) in teachmode.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [untitled.app/Contents/MacOS/untitled] Error 1
19:25:51: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project untitled (kit: Desktop Qt 5.4.0 clang 64bit)
When executing step "Make"