您好,欢迎来到思海网络,我们将竭诚为您提供优质的服务! 诚征网络推广 | 网站备案 | 帮助中心 | 软件下载 | 购买流程 | 付款方式 | 联系我们 [ 会员登录/注册 ]
促销推广
客服中心
业务咨询
有事点击这里…  531199185
有事点击这里…  61352289
点击这里给我发消息  81721488
有事点击这里…  376585780
有事点击这里…  872642803
有事点击这里…  459248018
有事点击这里…  61352288
有事点击这里…  380791050
技术支持
有事点击这里…  714236853
有事点击这里…  719304487
有事点击这里…  1208894568
有事点击这里…  61352289
在线客服
有事点击这里…  531199185
有事点击这里…  61352288
有事点击这里…  983054746
有事点击这里…  893984210
当前位置:首页 >> 技术文章 >> 文章浏览
技术文章

Linux下将Tinyxml编译为静态库

添加时间:2011-1-22  添加: admin 

一个应用需要在linux服务器上运行,不能保证每个服务器都有应用依赖的库,又懒得每个服务器都去安装下,也不太现实,于是就将应用所用到的库全部编译为静态库,直接丢到服务器 将其中的OUTPUT := xmltest一行修改为:OUTPUT := libtinyxml.a
将xmltest.cpp从SRCS:=tinyxml.cpp tinyxml-parser.cpp xmltest.cpp tinyxmlerror.cpp tinystr.cpp中删除,,注释掉xmltest.o:tinyxml.h tinystr.h。因为不需要将演示程序添加到动态库中。
将${LD} -o $@ ${LDFLAGS} ${OBJS} ${LIBS} ${EXTRA_LIBS}修改为:${AR} $@ ${LDFLAGS} ${OBJS} ${LIBS} ${EXTRA_LIBS}。
保存退出。
      4.执行make命令编译,即可在当前目录生成libtinyxml.a文件。

      5.调用测试,当前目录新建一个test.cpp文件,内容如下:

view sourceprint?01 #include "tinyxml.h"   

02 #include "tinystr.h"     

03 #include <iostream>     

04 using namespace std;   

05      

06 int main()   

07 {   

08     //创建一个XML的文档对象。   

09     TiXmlDocument *myDocument = new TiXmlDocument("test.xml");   

10     myDocument->LoadFile();   

11         

12     //获得根元素,即Persons。   

13     TiXmlElement *RootElement = myDocument->RootElement();   

14      

15     //输出根元素名称,即输出Persons。   

16     cout << RootElement->Value() << endl;   

17           

18     //获得第一个Person节点。   

19     TiXmlElement *FirstPerson = RootElement->FirstChildElement();   

20     //输出接点名Person   

21       

22     cout << FirstPerson->Value() << endl;   

23     //获得第一个Person的name节点和age节点和ID属性。   

24     TiXmlElement *NameElement = FirstPerson->FirstChildElement();   

25     TiXmlElement *AgeElement = NameElement->NextSiblingElement();   

26     TiXmlAttribute *IDAttribute = FirstPerson->FirstAttribute();   

27          

28     //输出第一个Person的name内容,即周星星;age内容,即20;ID属性,即1。   

29     cout << NameElement->FirstChild()->Value() << endl;   

30     cout << AgeElement->FirstChild()->Value() << endl;   

31     cout << IDAttribute->Value() << endl;   

32      

33         return 0;   

34 }

创建test.xml文件,内容如下:

view sourceprint?01 <Persons>   

02     <Person ID="1">   

03         <name>周星星</name>   

04         <age>20</age>   

05     </Person>   

分享到:

顶部 】 【 关闭
版权所有:佛山思海电脑网络有限公司 ©1998-2024 All Rights Reserved.
联系电话:(0757)22630313、22633833
中华人民共和国增值电信业务经营许可证: 粤B1.B2-20030321 备案号:粤B2-20030321-1
网站公安备案编号:44060602000007 交互式栏目专项备案编号:200303DD003  
察察 工商 网安 举报有奖  警警  手机打开网站