<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[运维进行时]]></title> 
<link>https://blog.liuts.com/index.php</link> 
<description><![CDATA[互联网运维与架构]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[运维进行时]]></copyright>
<item>
<link>https://blog.liuts.com/post//</link>
<title><![CDATA[编译C++的错误提示]]></title> 
<author>root &lt;admin@yourname.com&gt;</author>
<category><![CDATA[C/C++]]></category>
<pubDate>Fri, 17 Apr 2009 15:13:24 +0000</pubDate> 
<guid>https://blog.liuts.com/post//</guid> 
<description>
<![CDATA[ 
	<strong>config.h</strong><br/><textarea name="code" class="c" rows="15" cols="100">
#ifndef _CONFIG
#define _CONFIG

#include 
#include 

using namespace std;

class CConfig
&#123;
public:
explicit CConfig(const char* xmlFileName)
:mXmlConfigFile(xmlFileName),mRootElem(0)
&#123;
//加载配置文件
mXmlConfigFile.LoadFile();

//得到配置文件的根结点
mRootElem=mXmlConfigFile.RootElement();
&#125;

public:
//得到nodeName结点的值
string GetValue(const string& nodeName);

private:
//禁止默认构造函数被调用
//CMmsConfig();

private:
TiXmlDocument mXmlConfigFile;
TiXmlElement* mRootElem;

&#125;;
#endif
</textarea><br/><strong>main.cpp</strong><br/><textarea name="code" class="c" rows="15" cols="100">
#include 
#include "config.h"
using namespace std;

string CConfig::GetValue(const string& nodeName)
&#123;
if(!mRootElem)
&#123;
cout<<"读取根结点出错"< return "";
&#125;

TiXmlElement* pElem=mRootElem->FirstChildElement(nodeName.c_str());
if(!pElem)
&#123;
cout<<"读取"< return "";
&#125;

return pElem->GetText();

&#125;

int main()
&#123;
CConfig xmlConfig("XmlConfig.xml");

//获取Author的值
string author = xmlConfig.GetValue("Author");
cout<<"Author:"< 
//获取Site的值
string site = xmlConfig.GetValue("Site");
cout<<"Site:"< 
//获取Desc的值
string desc = xmlConfig.GetValue("Desc");
cout<<"Desc:"<
return 0;
&#125;
</textarea><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>./configure通过，make时提示：<br/>............<br/>nagios_rsync.o: In function `~TiXmlDocument':<br/>src/tinyxml.h:1401: undefined reference to `vtable for TiXmlDocument'<br/>src/tinyxml.h:1401: undefined reference to `TiXmlNode::~TiXmlNode()'<br/>nagios_rsync.o: In function `CConfig':<br/>src/config.h:33: undefined reference to `TiXmlDocument::TiXmlDocument(char const*)'<br/>src/config.h:36: undefined reference to `TiXmlDocument::LoadFile(TiXmlEncoding)'<br/>nagios_rsync.o: In function `TiXmlNode::FirstChildElement(char const*)':<br/>src/tinyxml.h:673: undefined reference to `TiXmlNode::FirstChildElement(char const*) const'<br/>collect2: ld returned 1 exit status<br/>make: *** [nagios_rsync] Error 1<br/>*** Exited with status: 2 ***<br/></div></div><br/>因为用到tinyxml包，程序找不到其它相关模块。<br/>在config.h中添加：<br/><textarea name="code" class="c" rows="15" cols="100">
#include <TINYXML.CPP>
#include <TINYSTR.H>
#include <TINYSTR.CPP>
#include <TINYXMLPARSER.CPP>
#include <TINYXMLERROR.CPP>
</textarea><br/>就正常了。 <br/>Tags - <a href="https://blog.liuts.com/tags/%25E7%25BC%2596%25E8%25AF%2591c%252B%252B/" rel="tag">编译c++</a>
]]>
</description>
</item><item>
<link>https://blog.liuts.com/post//#blogcomment</link>
<title><![CDATA[[评论] 编译C++的错误提示]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://blog.liuts.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>