Fedaora14 下编译xerces+icu
Xerces 是解析xml的库。
使用icu可以支持中文。
下载ICU和xerces 软件
官网是:http://www.icu-project.org/
或ftp://ftp.software.ibm.com/software/globalization/icu/3.4下载icu-3.4.tgzx.
本从已经下载了icu4c-3_6-src.tar 和xerces-c-3.1.1.tar
编译icu
首先编译安装icu. 默认是在64位编译,如果需求32位编译,请参与网上其他的帖子。
1. 解压icu. Tar -xficu4c-3_6-src.tar 解压出的目录为:icu
2. 设置环境变量
Export ICUROOT=xxx/xxx/xml/icu64
Echo $ICUROOT
Export LIBPATH=xxx/xxx/xml/icu64/lib:LIBPATH
Echo $LIBPATH
Export PATH=xxx/xxx/xml/icu64/bin:$PATH
Echo $PATH
3. Cd到步骤1解压出来的目录icu下的source目录. Cd /xxx/icu/source.
4. Configure
./Configure --prefix=xxxx/xxx/xml/icu64 --disable-shared --enable-static
5. Gmake
6. Make install
可能会报错误:
ParagraphLayout.cpp:801:6:错误: #elif 后没有表达式
本文直接到错的文件里,在#elif 后加上班1. 即#elif 1. 永远为真。
编译xerces
编译xerces 的步骤与icu类似:
1. 解压xerces-c-3.1.1.tar 解压出的目录是xerces-c-3.1.1
Tar -xf xerces-c-3.1.1.tar
2. 设置环境变量
Export XERCESROOT=xxx/xxxx/xerces-c-3.1.1
设置为xerces-c解压出来的目录。
Export LIBPATH=xxx/xxxx/xerces-c-3.1.1:$LIBPATH
3. Cd 到xerces-c-3.1.1.
4. Configure --enable-transcoder-icu --endable-msgloader-icu--prefix=/xxx/xxx/xml/xerces --disable-shared
5. Gmake
6. Make install
验证:
看看能不能转换成汉字编码,如失败,运行示例会有下列错误:
Could not create a converter fpr encoding:GBK
编译成功后,可使用XERCESROOT/bin/运行demo
./SAX2Pirnt –x=GBK test.xml
Makefile 环境
可以看一下安装目录的include 和lib
Cd /xxx/xxx/xerces;ls
有include 和lib以及bin目录:
其中lib目录下面有2个文件和一个目录pkgconfig:
Libxerces-c.a libxerces-c.la pkgconfig
Libxerces-c.la 和pkgconfig其实说明makefile里面要如何添加路径和参数。
把lib 和include 两个文件cp到工程目录下。
在makefile中加入库xerces-c
如L../libxml/xerces-c -lnsl –lpthread–lcurl
注意:这里要加上-lnsl –lpthread –lcurl. 在libxerces-c.la里有说明。否则demo会编译不过
包括头文件路径:
如I../inc_xml
这样,xerces+icu就应用到工程中了。