I am a little confused, I am trying to develop a simple application.
Application Flow: MainWindow -> Dialog 1 -> Dialog 2.
MainWindow imports Dialog1.h and Dialog1.h imports Dialog2.h
1) If I import TinyXML Libraries in both Dialog1.cpp and Dialog2.cpp, the compiler throws following error: duplicate symbol **RANDOM TINYXML CLASS* in: Dialog1.o Dialog2.o
2) As Dialog1.h imports Dialog2.h, Even if I try to import TinyXML libraries in only Dialog2.h, I still get following error: duplicate symbol **RANDOM TINYXML CLASS* in: mainwindow.o moc_Dialog2.o
I am not importing anything in mainwindow. Still the error persists.
Any help on where I am going wrong?
Error Log(There are 732, just copy pasted a bunch):
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"
Note: When I include the files in only Dialog2.cpp, the project compiles and all functions work as expected. The problem only occurs when I place it in the header file. My include directives for TinyXML:-
#include <tinystr.h>
#include <tinyxml.h>
#include <tinystr.cpp>
#include <tinyxmlerror.cpp
#include <tinyxml.cpp>
#include <tinyxmlparser.cpp>
If I only include the source files such as:
#include <tinystr.h>
#include <tinyxml.h>
I get the following error log:
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"
Don't include the source files, that's what's causing your problem!
Include only the header-files, and then compile and link the source files as you do with your own source files.
The source file contains the definitions of all functions, and you can only have a single definition in your program.