有坑,小心!!!mxml安装记录

转:
http://blog.sina.com.cn/s/blog_88ea0ce70101a708.html
https://blog.csdn.net/bbzhaohui/article/details/71512599
1.源码获取路径:

http://michaelrsweet.github.io/mxml/

可以直接下载.tar.gz包解压安装,或者直接通过github fork到自己的仓库,git到自己本地安装,关于github和git源码在下篇中再讲,现在讲解如何通过.tar.gz包安装。

现假定你已获取源码包并已成功放入到虚拟机Ubuntu目录下。

关于如何把文件从window传到虚拟机安装的系统中,可自行百度,或者有必要的话,下次再开篇博文。

2.首先解压mxml-2.10.tar.gz文件:

tar -xzvf mxml-2.10.tar.gz

3.编译安装

进入到解压后的文件目录:

设置环境./configure
编译make
安装 make install 注意root权限才可以安装,否则会提示权限不够 sudo make install
以上步骤顺利完成后,mini_xml库就已经安装到你的Linux系统中了。

以后就可以直接调用头文件 #include “mxml.h”使用了。

4.编译自带测试程序

下面用源码中自带的测试程序,先了解下大致功能

源码中有一个testmxml.c的文件就是测试程序,现编译成可执行文件

gcc -o testmxml testmxml.c

提示错误:

testmxml.c:(.text+0x1655):对‘mxmlSAXLoadFile’未定义的引用

/tmp/cc9KVjbn.o:在函数‘type_cb’中:

testmxml.c:(.text+0x1827):对‘mxmlElementGetAttr’未定义的引用

collect2: error: ld returned 1 exit status

动态链接库未在编译时链接进去,修改

gcc -o testmxml testmxml.c -lmxml

再编译:

//usr/local/lib/libmxml.so:对‘pthread_getspecific’未定义的引用

//usr/local/lib/libmxml.so:对‘pthread_key_create’未定义的引用

//usr/local/lib/libmxml.so:对‘pthread_once’未定义的引用

//usr/local/lib/libmxml.so:对‘pthread_setspecific’未定义的引用

//usr/local/lib/libmxml.so:对‘pthread_key_delete’未定义的引用

collect2: error: ld returned 1 exit status

还是有错误,看提示信息是pthread线程相关动态库未链接进来,继续修改

gcc -o testmxml testmxml.c -lmxml -lpthread

这次便编译成功了
5.出现问题吧!!!
出现这个问题没?
:error while loading shared libraries: libmxml.so.1: cannot open sharedobject

这是由于共享库文件安装到了/usr/local/lib中,程序按照默认共享路径找不到该共享文件。因此,需要将目录/usr/local/lib加到系统共享库配置文件/etc/ld.so.conf中
#cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
#include “/usr/local/lib” >> /etc/ld.so.conf
#ldconfig
注:ldconfig命令的用途:在默认搜索目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录下,搜索出可共享的动态链接库(格式如:lib*.so*),进而创建出动态装入程序(ld.so)所需的连接和缓存文件.缓存文件默认为/etc/ld.so.cache,此文件保存已排好序的动态链接库名字列表.

6.运行

./testmxml

提示信息:

Usage: testmxml filename.xml [string-output.xml]

说明输入参数需要有一个.xml文件,或者一个可选的输出.xml文件。

第一个文件必须要在testmxml同一目录下存在

如在源程序中已经存在一份test.xml文件

重新运行:

./testmxml test.xml

就会把test.xml文件中的内容显示出来了。

如果运行:

./testmxml test.xml testnew.xml

就会把test.xml文件中的内容复制到testnew.xml文件中,同时会显示在界面上。

猜你喜欢

转载自blog.csdn.net/Travelerwz/article/details/82696673