欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

libxml2 安装使用

程序员文章站 2022-06-09 18:28:07
...

libxml2 安装使用 现在的最新版本是2.6.30,可以到http://ftp.gnome.org/pub/GNOME/sources/libxml2/2.6/ 下载。 安装很简单,三部走。 view plaincopy to clipboardprint? 01安装 02.#./configure 03.#make 04.#make install 05测试 06.#make tests 07卸载

libxml2 安装使用

现在的最新版本是2.6.30,可以到http://ftp.gnome.org/pub/GNOME/sources/libxml2/2.6/ 下载。

安装很简单,三部走。

view plaincopy to clipboardprint?
01安装
02.#./configure
03.#make
04.#make install
05测试
06.#make tests
07卸载
08.#make uninstall

如果不需要特别的定制,在configure阶段可以直接默认。 libxml2将默认把头文件与库安装在/usr/local/include/libxml2/libxml目录下。因此可能会让你在第一次编译自己的程序时遇到头文件“no such file”的错误

libxml2提供了解决方法,它很体贴地在/usr/local/bin目录下为您提供了xml2-config、xmlcatalog、xmllint三个便利的工具。其中xml2-config在编译时用得到。


[root@Amanda ~]# xml2-config
Usage: xml2-config [OPTION]
Known values for OPTION are:
--prefix=DIR change libxml prefix [default /usr/local]
--exec-prefix=DIR change libxml exec prefix [default /usr/local]
--libs print library linking information
--cflags print pre-processor and compiler flags
--modules module support enabled
--help display this help and exit
--version output version information

这里说到编译时用到的参数: --cflags和--libs,帮助上说明这个为工程编译时提供辅助。它们提供的信息如下:

view plaincopy to clipboardprint?
01.[root@Amanda ~]# xml2-config --cflags
02.-I/usr/local/include/libxml2
03.[root@Amanda ~]# xml2-config --libs
04.-L/usr/local/lib -lxml2 -lz -lm
[root@Amanda ~]# xml2-config --cflags
-I/usr/local/include/libxml2
[root@Amanda ~]# xml2-config --libs
-L/usr/local/lib -lxml2 -lz -lm

所以在编译自己的测试程序时,可以直接使用 #gcc -I /usr/local/include/libxml2 -L/usr/local/lib -lxml2 -lz -lm -o test test.c 。

或者加入到makefile中,例如:


CFLAGS=`xml2-config --cflags`

LIBS=`xml2-config --libs`

注:若编译出错:

/usr/include/bits/fcntl2.h:51: 错误: 调用‘__open_missing_mode’,声明有错误属性:open with O_CREAT in second argument needs 3 arguments


解决方法:
打开目录下的nanohttp.c,第1588行由
fd = open(filename, O_CREAT | O_WRONLY);更换为
fd = open(filename, O_CREAT | O_WRONLY,0777);

参考资料:
http://temix.blog.163.com/blog/static/364133200810237854799/

http://linux.chinaunix.net/techdoc/system/2008/11/08/1044060.shtml
https://bugs.launchpad.net/ubuntu/+source/gcc-4.3/+bug/286565