Home Database Mysql Tutorial Ubuntu12.4.04下libxml2的安装和使用

Ubuntu12.4.04下libxml2的安装和使用

Jun 07, 2016 pm 03:24 PM
use about Install

关于libxml2库的详细信息的查看方法请查看: http://blog.csdn.net/wangkai_123456/article/details/25710971 libxml2库的安装方法: sudo apt-get install libxml2 sudo apt-get install libxml2-dev 利用以上命令安装完软件包后可以利用以下命令来查看软件

        关于libxml2库的详细信息的查看方法请查看:http://blog.csdn.net/wangkai_123456/article/details/25710971


        libxml2库的安装方法:

sudo apt-get install libxml2

sudo apt-get install libxml2-dev


        利用以上命令安装完软件包后可以利用以下命令来查看软件包的状态(确定是否安装成功)

dpkg -s libxml2-dev

也可以用如下命令(得到的结果是一样的):

dpkg-query -s libxml2-dev


        软件安装好后,默认情况下,libxml2对应的头文件均放置在/usr/include/libxml2/libxml目录下,这一信息可利用如下两个命令查看(任一命令都能查看到相关信息)

dpkg -L libxml2-dev

xml2-config --cflags


       libxml2的库文件放置在/usr/lib/i386-linux-gnu目录下,这一信息可利用如下两个命令查看(任一命令都能查看到相关信息

dpkg -L libxml2-dev

xml2-config --libs


        对应libxml2有一个工具,名字为xml2-config,xml2-config所在的目录为/usr/bin,其实这是一个shell脚本,关于xml2-config的详细信息可以通过如下命令来查看

man xml2-config


        安装后libxml2库后,就可以开始进行基于libxml2库的开发了。现有以下一段程序,程序文件名为CreateXmlFile.c,是基于libxml2库开发的。代码如下

/**********************************
created: 2014/05/12
filename: CreateXmlFile.c
auther: wang kai
depend: libxml2.lib
purpose: 创建一个xml文件
**********************************/

#include<stdio.h>
#include<libxml>
#include<libxml>

int main(int argc, char **argv)
{
	//Define document pointer
	xmlDocPtr doc = xmlNewDoc(BAD_CAST"1.0");

    //Define node pointer
	xmlNodePtr root_node = xmlNewNode(NULL,BAD_CAST"root");

	//Set the root element of the document
	xmlDocSetRootElement(doc,root_node);

	//Create child nodes directly in the root node
	xmlNewTextChild(root_node,NULL,BAD_CAST"newnode1",BAD_CAST"newnode1 content");
	xmlNewTextChild(root_node,NULL,BAD_CAST"newnode2",BAD_CAST"newnode2 content");

	//Create a new node
	xmlNodePtr node = xmlNewNode(NULL,BAD_CAST"node2");
	//Create a new text node
	xmlNodePtr content = xmlNewText(BAD_CAST"NODE CONTENT");

	//Add a new node to parent
	xmlAddChild(root_node,node);
	xmlAddChild(node,content);
	//Create a new property carried by a node
	xmlNewProp(node,BAD_CAST"attribute",BAD_CAST"yes");

	//Create a son and grandson node element
	node = xmlNewNode(NULL,BAD_CAST"son");
	xmlAddChild(root_node,node);
	xmlNodePtr grandson = xmlNewNode(NULL,BAD_CAST"grandson");
	xmlAddChild(node,grandson);
	xmlAddChild(grandson,xmlNewText(BAD_CAST"THis is a grandson node"));
	
	//Dump an XML document to a file
	int nRel = xmlSaveFile("CreatedXml.xml",doc);
	if(nRel != -1)
		printf("一个xml文档被创建,写入 %d 个字节\n",nRel);
	
	//Free up all the structures used by a document,tree included
	xmlFreeDoc(doc);
	//printf("Hello World!\n");
	return 0;
}</libxml></libxml></stdio.h>
Copy after login
         对这个程序进行编译时,可用以下命令

gcc -I/usr/include/libxml2  CreateXmlFile.c -o CreateXmlFile -L /usr/lib/i386-linux-gnu -lxml2

         其中,-I参数是为了指定gcc编译器查找头文件的路径,-L参数是为了指定libxml2库文件所在的路径,最后的 

  -lxml2指定具体的库文件。(-lxml2一定要放在命令的最后位置,不然会出现找不到链接库的错误,如下图所示)

Ubuntu12.4.04下libxml2的安装和使用

具体为什么一定要把-lxml2放在最后的位置,本人目前还没弄明白,有待进一步研究

        

        编译命令也可以写成如下形式:

gcc `xml2-config --cflags` -L /usr/lib/i386-linux-gnu CreateXmlFile.c -o CreateXmlFile -lxml2

gcc `xml2-config --cflags`  CreateXmlFile.c -o CreateXmlFile -L /usr/lib/i386-linux-gnu -lxml2

gcc CreateXmlFile.c -o CreateXmlFile `xml2-config --cflags --libs`

        形式虽然不一样,其实命令的实际内容是一样的。因为命令xml2-config --cflags的执行结果为

-I/usr/include/libxml2         (指明include头文件所在的目录)

        命令xml2-config --libs的执行结果为

-L/usr/lib/i386-linux-gnu -lxml2   (指明libxml2库文件所在的目录以及具体的库文件)

      (不管写成何种形式,只要保证 -lxml2 在编译命令的最后位置即可)






Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What software is crystaldiskmark? -How to use crystaldiskmark? What software is crystaldiskmark? -How to use crystaldiskmark? Mar 18, 2024 pm 02:58 PM

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

What should I do if Baidu Netdisk is downloaded successfully but cannot be installed? What should I do if Baidu Netdisk is downloaded successfully but cannot be installed? Mar 13, 2024 pm 10:22 PM

If you have successfully downloaded the installation file of Baidu Netdisk, but cannot install it normally, it may be that there is an error in the integrity of the software file or there is a problem with the residual files and registry entries. Let this site take care of it for users. Let’s introduce the analysis of the problem that Baidu Netdisk is successfully downloaded but cannot be installed. Analysis of the problem that Baidu Netdisk downloaded successfully but could not be installed 1. Check the integrity of the installation file: Make sure that the downloaded installation file is complete and not damaged. You can download it again, or try to download the installation file from another trusted source. 2. Turn off anti-virus software and firewall: Some anti-virus software or firewall programs may prevent the installation program from running properly. Try disabling or exiting the anti-virus software and firewall, then re-run the installation

How to download foobar2000? -How to use foobar2000 How to download foobar2000? -How to use foobar2000 Mar 18, 2024 am 10:58 AM

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

How to use NetEase Mailbox Master How to use NetEase Mailbox Master Mar 27, 2024 pm 05:32 PM

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

How to install Android apps on Linux? How to install Android apps on Linux? Mar 19, 2024 am 11:15 AM

Installing Android applications on Linux has always been a concern for many users. Especially for Linux users who like to use Android applications, it is very important to master how to install Android applications on Linux systems. Although running Android applications directly on Linux is not as simple as on the Android platform, by using emulators or third-party tools, we can still happily enjoy Android applications on Linux. The following will introduce how to install Android applications on Linux systems.

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? Apr 26, 2024 am 09:40 AM

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

How to install Podman on Ubuntu 24.04 How to install Podman on Ubuntu 24.04 Mar 22, 2024 am 11:26 AM

If you have used Docker, you must understand daemons, containers, and their functions. A daemon is a service that runs in the background when a container is already in use in any system. Podman is a free management tool for managing and creating containers without relying on any daemon such as Docker. Therefore, it has advantages in managing containers without the need for long-term backend services. Additionally, Podman does not require root-level permissions to be used. This guide discusses in detail how to install Podman on Ubuntu24. To update the system, we first need to update the system and open the Terminal shell of Ubuntu24. During both installation and upgrade processes, we need to use the command line. a simple

See all articles