tinyXML链接出错!!!!!!!!!!!!11急急急!!!!!!

Xiaoloveliuforever 2011-05-05 04:43:02
最近在研究tinyxml操作XML文件,
这是我的代码:(写的很乱,仅测试用。。。)

#include "tinyxml.h"
#include <iostream>
using namespace std;


void main( int argc, char*argv[] )
{
TiXmlDocument doc;

TiXmlElement* pmsg = NULL;
TiXmlDeclaration *pdecl = new TiXmlDeclaration( "1.0", "","");
if ( NULL ==pdecl )
{
return;
}
doc.LinkEndChild( pdecl );


TiXmlElement *pRoot = new TiXmlElement( "MyApp" );
if ( NULL ==pRoot )
{
return;
}
doc.LinkEndChild( pRoot );//¸ùÔªËØ


TiXmlComment *pComment = new TiXmlComment();
if ( NULL == pComment )
{
return;
}
pComment->SetValue( "Setting for MyApp" );

pRoot->LinkEndChild( pComment );
TiXmlElement *pMsgs = new TiXmlElement( "Messages" );
if ( NULL == pMsgs )
{
return;
}
pRoot->LinkEndChild( pMsgs );


pmsg = new TiXmlElement( "Welcome" );
pmsg->LinkEndChild( new TiXmlText( "Welcome to MyApp" ) );
pMsgs->LinkEndChild( pmsg );

pmsg = new TiXmlElement( "FaraWell" );
pmsg->LinkEndChild( new TiXmlText( "Thhank you for using MyApp" ) );
pMsgs->LinkEndChild( pmsg );


TiXmlElement *pWindows = new TiXmlElement( "Windows" );
pRoot->LinkEndChild( pWindows );//¸ùÔªËØÖвåÈëÐÂÔªËØWindows
pWindows->SetAttribute( "name", "MainFrame");
pWindows->SetAttribute( "x", 5 );
pWindows->SetAttribute( "y", 15 );
pWindows->SetAttribute( "w", 400 );
pWindows->SetAttribute( "h", 250 );


TiXmlElement *pCxn = new TiXmlElement( "Connection" );
pRoot->LinkEndChild( pCxn );
pCxn->SetAttribute( "ip", "192.168.0.1" );
pCxn->SetDoubleAttribute( "timeout", 123.456 );

//dump_to_stdout( &doc );
bool isOk = doc.SaveFile( "E:\\cjbtest\\TinyXMLdemo\\test1\\appsetting.xml" );


TiXmlDocument *pDocument = new TiXmlDocument( "E:\\cjbtest\\TinyXMLdemo\\test1\\appsetting.xml" );
if ( NULL != pDocument )
{
if ( !pDocument->LoadFile() )
{
return;
}

TiXmlElement *pRootElement = pDocument->FirstChildElement( "MyApp" );
if ( NULL != pRootElement )
{

TiXmlElement *pMsgElement = pRootElement->FirstChildElement( "Messages" );
if ( NULL != pMsgElement )
{
TiXmlElement *pWelElement = pMsgElement->FirstChildElement( "Welcome" );
if ( NULL != pWelElement )
{
std::cout<<pWelElement->GetText()<<std::endl;
}

TiXmlElement *pFarawell = pWelElement->NextSiblingElement( "FaraWell" );
if ( NULL != pFarawell )
{
std::cout<<pFarawell->GetText()<<std::endl;
}
}
else
{
return;
}

TiXmlElement *pWindowsElement = pMsgElement->NextSiblingElement( "Windows" );
if ( NULL != pWindowsElement )
{
TiXmlAttribute *pFistAttribute = pWindowsElement->FirstAttribute();
if ( NULL != pFistAttribute )
{
std::cout<<pFistAttribute->IntValue()<<std::endl;
}


TiXmlAttribute *pSecond = pFistAttribute->Next();
if ( NULL != pSecond )
{
std::cout<<pSecond->IntValue()<<std::endl;
}


TiXmlAttribute *pth = pSecond->Next();
if ( NULL != pth )
{
std::cout<<pth->IntValue()<<std::endl;
}


TiXmlAttribute *pFouth = pth->Next();
if ( NULL != pFouth )
{
std::cout<<pFouth->IntValue()<<std::endl;
}

}
else
{
}



TiXmlElement *pConnection = pWindowsElement->NextSiblingElement( "Connection" );
if ( NULL != pConnection )
{
TiXmlAttribute *pConFist = pConnection->FirstAttribute();
if ( NULL != pConFist )
{
std::cout<<pConFist->Value()<<std::endl;
}

TiXmlAttribute *pConSec = pConFist->Next();
if ( NULL != pConSec )
{
std::cout<<pConSec->DoubleValue()<<std::endl;
}

}
else
{
return;
}
}
else
{
return;
}
}

}


...全文
505 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
20楼的你的代码我下了看了,和我做的差不多,可为什么我编译不过呢,求教 QQ710912527  王龙,谢谢了。
  • 打赏
  • 举报
回复
我这边新创建一个工程把TinyXML的源码全部放到这个工程里面也就 是tinyxml.h等等文件,主程序如下:
#include "stdafx.h"
#include "XML.h"
#include "tinyxml.h"
#include <string>
#include <iostream>
#include <tinyxml.h>
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
TiXmlDocument doc;
return 0;
}
就这几句话他就报错:
XML.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall TiXmlDocument::TiXmlDocument(void)" (??0TiXmlDocument@@QAE@XZ),该符号在函数 _wWinMain@16 中被引用
1>XML.obj : error LNK2019: 无法解析的外部符号 "public: virtual __thiscall TiXmlNode::~TiXmlNode(void)" (??1TiXmlNode@@UAE@XZ),该符号在函数 "public: virtual __thiscall TiXmlDocument::~TiXmlDocument(void)" (??1TiXmlDocument@@UAE@XZ) 中被引用
1>XML.obj : error LNK2001: 无法解析的外部符号 "public: virtual void __thiscall TiXmlDocument::Print(struct _iobuf *,int)const " (?Print@TiXmlDocument@@UBEXPAU_iobuf@@H@Z)
1>XML.obj : error LNK2001: 无法解析的外部符号 "public: virtual char const * __thiscall TiXmlDocument::Parse(char const *,class TiXmlParsingData *,enum TiXmlEncoding)" (?Parse@TiXmlDocument@@UAEPBDPBDPAVTiXmlParsingData@@W4TiXmlEncoding@@@Z)
1>XML.obj : error LNK2001: 无法解析的外部符号 "protected: virtual class TiXmlNode * __thiscall TiXmlDocument::Clone(void)const " (?Clone@TiXmlDocument@@MBEPAVTiXmlNode@@XZ)
1>XML.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall TiXmlDocument::Accept(class TiXmlVisitor *)const " (?Accept@TiXmlDocument@@UBE_NPAVTiXmlVisitor@@@Z)
1>XML.obj : error LNK2001: 无法解析的外部符号 "private: static struct TiXmlString::Rep TiXmlString::nullrep_" (?nullrep_@TiXmlString@@0URep@1@A)
1>F:\XML\Debug\XML.exe : fatal error LNK1120: 7 个无法解析的外部命令
我没有用到dll啊。我这边下载的版本只有源文件没有工程我没有手动生成DLL。请问下直接引用这个源码还要设置什么啊,纠结了好几天了。
wencan2010 2011-05-18
  • 打赏
  • 举报
回复
我也是链接失败
环境vc6
xunxun 2011-05-07
  • 打赏
  • 举报
回复
error LNK2001: unresolved external symbol ___security_cookie

这个问题据信是由于你的VC启用了/GS导致的,手动加入/GS-即可

http://www.pcreview.co.uk/forums/unresolved-external-symbol-___security_cookie-t1428747.html
king8902 2011-05-07
  • 打赏
  • 举报
回复
http://download.csdn.net/source/3246292
这个或许对你有帮助
Xiaoloveliuforever 2011-05-06
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 ljt3969636 的回复:]

一般可能是你的lib是debug版的所以只能用,而在主程序的release版下不成,反之亦然,请保证库文件和调用库文件的程序生成版本一致
[/Quote]

lib文件是我用VC6编译生成出来的,而且我肯定都是用的release版本的
ljt3969636 2011-05-05
  • 打赏
  • 举报
回复
一般可能是你的lib是debug版的所以只能用,而在主程序的release版下不成,反之亦然,请保证库文件和调用库文件的程序生成版本一致
ljt3969636 2011-05-05
  • 打赏
  • 举报
回复
我的意思是你用什么生成的lib文件,vc还是下载xml自带的脚本或者make文件
Xiaoloveliuforever 2011-05-05
  • 打赏
  • 举报
回复
呵呵
下的东西里面有好几个项目
哪个是读取XML文件的啊
Meteor_Code 2011-05-05
  • 打赏
  • 举报
回复
release的tinyxml.lib可以连接任何版本的工程
debug版本的tinyxml.lib只能连接debug的工程
这样厚道了吗?
Xiaoloveliuforever 2011-05-05
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 meteor_code 的回复:]

http://download.csdn.net/source/3101722
这是一个大实例,我写过的程序,里面就有tinyxml的源代码和库
注意final_skb.cpp中
#pragma comment(lib, "tinyxml.lib")
就是连接tinyxml.lib
得到这个例子你得用下载积分
[/Quote]

果然是个不厚道的家伙 哈哈 - -
Xiaoloveliuforever 2011-05-05
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 meteor_code 的回复:]

引用 7 楼 xiaoloveliuforever 的回复:
我了个去也
debug 编译链接都成功
release 编译成功 链接失败

你应该连接release版本的tinyxml.lib库
[/Quote]

我肯定我的tinyxml.lib是release版本编译出来的
Meteor_Code 2011-05-05
  • 打赏
  • 举报
回复
http://download.csdn.net/source/3101722
这是一个大实例,我写过的程序,里面就有tinyxml的源代码和库
注意final_skb.cpp中
#pragma comment(lib, "tinyxml.lib")
就是连接tinyxml.lib
得到这个例子你得用下载积分
Xiaoloveliuforever 2011-05-05
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 meteor_code 的回复:]

连接tinyxml.lib库
我用从来没出过错啊
[/Quote]

。。。。。
那 求个小实例 谢谢
Meteor_Code 2011-05-05
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 xiaoloveliuforever 的回复:]
我了个去也
debug 编译链接都成功
release 编译成功 链接失败
[/Quote]
你应该连接release版本的tinyxml.lib库
Meteor_Code 2011-05-05
  • 打赏
  • 举报
回复
连接tinyxml.lib库
我用从来没出过错啊
Xiaoloveliuforever 2011-05-05
  • 打赏
  • 举报
回复
这是什么个情况。。。
我头一次碰见啊
Xiaoloveliuforever 2011-05-05
  • 打赏
  • 举报
回复
我了个去也
debug 编译链接都成功
release 编译成功 链接失败
Xiaoloveliuforever 2011-05-05
  • 打赏
  • 举报
回复
lib文件时下载的tinyXML的源码 编译生成的
ljt3969636 2011-05-05
  • 打赏
  • 举报
回复
lib文件是怎么生成的用自带的makefile还是什么?另外debug模式下连接时输出什么
加载更多回复(3)

64,637

社区成员

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

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