xercesc_c++3.1.1编译出错求助

wuzhou1234 2011-10-08 05:12:05
各位大侠,我在unbutu下装了xerces_c++3.1,安装过程如下:
下载xerces-c++3.0.1 tar包
(1)gzip -d xercess---.tar.gz
(2)tar -xvf xerces---.tar
(3)cd xer...3.0.1
(4)./configure
(5)make
(6)cd src
(7)make install
安装完成后,在/usr/local/lib/下,有xerces的.a和.so文件,在/usr/local/include/下有xerces的源代码
(8)把/usr/local/lib下的文件拷贝到/usr/lib 下。

现在写一个简单例子:
// CXML.h

#ifndef XML_PARSER_HPP
#define XML_PARSER_HPP
#include <xercesc/util/TransService.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMDocumentType.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMNodeIterator.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
#include <xercesc/dom/DOMText.hpp>
#include <xercesc/dom/DOMAttr.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/framework/XMLFormatter.hpp>
#include <xercesc/util/XMLString.hpp>
#include <stdlib.h>
#include <string>
#include <vector>
#include <stdexcept>
using namespace std;
using namespace xercesc_3_1;

class CXML
{
public:
CXML();
~CXML();
XMLTransService::Codes tranServiceCode;
void xmlParser(string&) throw(std::runtime_error);
private:
xercesc::XercesDOMParser *m_DOMXmlParser;
};
#endif

// CXML.cpp
#include <string>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <list>
#include <stdio.h>
#include "CXML.h"

CXML::CXML()
{
try
{
// Initialize Xerces-C++ library
XMLPlatformUtils::Initialize();
}
catch(xercesc::XMLException & excp)
{
char* msg = XMLString::transcode(excp.getMessage());
printf("XML toolkit initialization error: %s/n", msg);
XMLString::release(&msg);
}

m_DOMXmlParser = new XercesDOMParser;
}

CXML::~CXML()
{
try
{
XMLPlatformUtils::Terminate();
}
catch(XMLException& excp)
{
char* msg = XMLString::transcode(excp.getMessage());
printf("XML toolkit terminate error: %s/n", msg);
XMLString::release(&msg);
}
}

void CXML::xmlParser(string & xmlFile) throw( std::runtime_error )
{

m_DOMXmlParser->setValidationScheme( XercesDOMParser::Val_Auto );
m_DOMXmlParser->setDoNamespaces( false );
m_DOMXmlParser->setDoSchema( false );
m_DOMXmlParser->setLoadExternalDTD( false );
try
{
m_DOMXmlParser->parse(xmlFile.c_str()) ;

DOMDocument* xmlDoc = m_DOMXmlParser->getDocument();
DOMElement *pRoot = xmlDoc->getDocumentElement();
if (!pRoot )
{
throw(std::runtime_error( "empty XML document" ));
}


// create a walker to visit all text nodes.
/**********************************************
DOMTreeWalker *walker =
xmlDoc->createTreeWalker(pRoot, DOMNodeFilter::SHOW_TEXT, NULL, true);
// use the tree walker to print out the text nodes.
std::cout<< "TreeWalker:/n";

for (DOMNode *current = walker->nextNode(); current != 0; current = walker->nextNode() )
{

char *strValue = XMLString::transcode( current->getNodeValue() );
std::cout <<strValue;
XMLString::release(&strValue);
}
std::cout << std::endl;

*************************************************/

// create an iterator to visit all text nodes.
DOMNodeIterator* iterator = xmlDoc->createNodeIterator(pRoot,
DOMNodeFilter::SHOW_TEXT, NULL, true);

// use the tree walker to print out the text nodes.
std::cout<< "iterator:/n";

for ( DOMNode * current = iterator->nextNode();
current != 0; current = iterator->nextNode())
{
string strValue =XMLString::transcode(current->getNodeValue());
std::cout <<strValue<<endl;
}

std::cout<< std::endl;

}
catch( xercesc::XMLException& excp )
{
char* msg = xercesc::XMLString::transcode( excp.getMessage() );
ostringstream errBuf;
errBuf << "Error parsing file: " << msg << flush;
XMLString::release( &msg );
}
}

int main(int argc ,char* argv[])
{
//if(argc!=2)
//{
// return 0;
//}
string xmlFile = "sample.xml";
CXML cxml;
cxml.xmlParser(xmlFile);
return 0;
}


编译时出现以下错误,由于帖子长度限制,省去了一些类似的错误,都是undefined reference to的错误,求指教:
CXML.cpp:(.text+0x61e): undefined reference to `xercesc_3_1::XMLPlatformUtils::fgMemoryManager'
CXML.cpp:(.text+0x635): undefined reference to `xercesc_3_1::XMLString::transcode(unsigned short const*, xercesc_3_1::MemoryManager*)'
CXML.cpp:(.text+0x688): undefined reference to `xercesc_3_1::XMLPlatformUtils::fgMemoryManager'
...全文
166 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuzhou1234 2011-10-08
  • 打赏
  • 举报
回复
不知道啊,我也是第一次接触这个东西,例子也是在网上copy的,但在VC6.0上可以编译通过。
pengzhixi 2011-10-08
  • 打赏
  • 举报
回复
XMLPlatformUtils的头文件是哪个?

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧