Compile Tinyxml into a static library in Linux

Source: Internet
Author: User
& Amp; nbsp; an application needs to run on a linux server. it is not realistic to ensure that each server has a library on which the application depends, nor to install each server, so compile all the databases used by the application as static databases and directly drop them on the server. This is an example where the application calls the xml configuration file and relies on the tinyxml Library. For more information, see Source: compile Tinyxml as a static library in Linux.

An application needs to run on a linux server. it cannot ensure that each server has a library on which the application depends, and it is not realistic to install each server, so compile all the databases used by the application as static databases and directly drop them on the server. This is the example where the application calls the xml configuration file and relies on the tinyxml Library.

1. download the tinyxml library and download it from the official website ,#.

2. decompress the downloaded package and decompress it to the test directory to go to the project directory.

3. use the vim editor to modify the Makefile file:

Change the OUTPUT: = xmltest line to: OUTPUT: = libtinyxml..
Delete xmltest. cpp from SRCS: = tinyxml. cpp tinyxml-parser.cpp xmltest. cpp tinyxmlerror. cpp tinystr. cpp, comment out xmltest. o: tinyxml. h tinystr. h. Because you do not need to add the demo program to the dynamic library.
Change $ {LD}-o $ {LDFLAGS }$ {OBJS }$ {LIBS }$ {EXTRA_LIBS}: $ {AR }$ @$ {LDFLAGS }$ {OBJS }$ {LIBS }$ {EXTRA_LIBS }.
Save and exit.
4. run the make command to compile the libtinyxml. a file in the current directory.

5. call the test and create a new test. cpp file in the current directory. the content is as follows:

View sourceprint? 01 # include "tinyxml. h" 02 # include "tinystr. h" 03 # include
 
  
04 using namespace std; 05 06 int main () 07 {08 // Create an XML document object. 09 TiXmlDocument * myDocument = new TiXmlDocument ("test. xml"); 10 myDocument-> LoadFile (); 11 12 // Obtain the root element, namely, Persons. 13 TiXmlElement * RootElement = myDocument-> RootElement (); 14 15 // output the root element name, namely, the output Persons. 16 cout <RootElement-> Value () <endl; 17 18 // obtain the first Person node. 19 TiXmlElement * FirstPerson = RootElement-> FirstChildElement (); 20 // output contact name Person 21 22 cout <FirstPerson-> Value () <endl; 23 // Obtain the name and age nodes and ID attributes of the first Person. 24 TiXmlElement * NameElement = FirstPerson-> FirstChildElement (); 25 TiXmlElement * AgeElement = NameElement-> NextSiblingElement (); 26 TiXmlAttribute * idattriement = FirstPerson-> firstattriement (); 27 28 // output the name of the first Person, that is, Zhou Xing; age content, that is, 20; ID attribute, that is, 1. 29 cout <NameElement-> FirstChild ()-> Value () <endl; 30 cout <AgeElement-> FirstChild ()-> Value () <endl; 31 cout <IDAttribute-> Value () <endl; 32 33 return 0; 34}
 

Create the test. xml file with the following content:

View sourceprint? 01
 
  
02
  
   
03
   
    
Zhou Xingxing
   04 2005
  06
  
   
07
   
    
Bai Jingjing
   08 1809
  10
 

Compile the current file and call libtinyxml.:

[root@server tinyxml]# g++ -o test test.cpp ./libtinyxml.a

Run the compiled program:

[Root @ server tinyxml] #./testPersonsPerson Zhou Xingwei 201

Put the compiled test and test. xml to another database without tinyxml, and the execution is successful.

The above is the content for compiling Tinyxml into a static library in Linux. For more information, see PHP Chinese network (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.