根据网上的这个例子编译,却出现一些“undefined reference to”的错误;
错误如下:
8-3.cpp:(.text+0x81): undefined reference to `TiXmlDocument::TiXmlDocument(char const*)'
8-3.cpp:(.text+0x94): undefined reference to `TiXmlDocument::LoadFile(TiXmlEncoding)'
8-3.cpp:(.text+0x1a7): undefined reference to `TiXmlElement::GetText() const'
8-3.cpp:(.text+0x1f0): undefined reference to `TiXmlElement::Attribute(char const*) const'
/tmp/cceasJCM.o: In function `TiXmlNode::FirstChildElement()':
8-3.cpp:(.text._ZN9TiXmlNode17FirstChildElementEv[TiXmlNode::FirstChildElement()]+0xd): undefined reference to `TiXmlNode::FirstChildElement() const'
/tmp/cceasJCM.o: In function `TiXmlNode::FirstChild(char const*)':
8-3.cpp:(.text._ZN9TiXmlNode10FirstChildEPKc[TiXmlNode::FirstChild(char const*)]+0x14): undefined reference to `TiXmlNode::FirstChild(char const*) const'
/tmp/cceasJCM.o: In function `TiXmlNode::NextSibling(char const*)':
8-3.cpp:(.text._ZN9TiXmlNode11NextSiblingEPKc[TiXmlNode::NextSibling(char const*)]+0x14): undefined reference to `TiXmlNode::NextSibling(char const*) const'
/tmp/cceasJCM.o: In function `TiXmlString::quit()':
8-3.cpp:(.text._ZN11TiXmlString4quitEv[TiXmlString::quit()]+0xc): undefined reference to `TiXmlString::nullrep_'
/tmp/cceasJCM.o: In function `TiXmlDocument::~TiXmlDocument()':
8-3.cpp:(.text._ZN13TiXmlDocumentD1Ev[TiXmlDocument::~TiXmlDocument()]+0xb): undefined reference to `vtable for TiXmlDocument'
8-3.cpp:(.text._ZN13TiXmlDocumentD1Ev[TiXmlDocument::~TiXmlDocument()]+0x24): undefined reference to `TiXmlNode::~TiXmlNode()'
collect2: ld 返回 1
根本没有安装的tinyxml相关的库文件把
也可能是安装时没装到linux默认的路径,g++找不到库文件
这种情况基本上可以说是找不到tinyxml的静态/动态库导致的。编译参数里面加上库路径。