坑爹的libxml2 for mingw 编译 (二)

本文介绍了在mingw环境下编译libxml2时遇到的问题,主要是由于makefile中使用cmd /C 命令导致的编译错误。解决方法是修改makefile中的相关代码,避免在mingw和cmd之间切换。
摘要由CSDN通过智能技术生成

makefile 中由于大量使用了cmd /C ""样式去执行mkdir和copy操作,导致mingw最后出错,因为会从mingw切换至cmd界面。因此需要把相关代码进行修改.



# Makefile for libxml2, specific for Windows, GCC (mingw) and GNU make.
#
# Take a look at the beginning and modify the variables to suit your 
# environment. Having done that, you can do a
#
# nmake [all]     to build the libxml and the accompanying utilities.
# nmake clean     to remove all compiler output files and return to a
#                 clean state.
# nmake rebuild   to rebuild everything from scratch. This basically does
#                 a 'nmake clean' and then a 'nmake all'.
# nmake install   to install the library and its header files.
#
# November 2002, Igor Zlatkovic <igor@zlatkovic.com>

# There should never be a need to modify anything below this line.
# ----------------------------------------------------------------

AUTOCONF = .\config.mingw
include $(AUTOCONF)

# Names of various input and output components.
XML_NAME = xml2
XML_BASENAME = lib$(XML_NAME)
XML_SO = $(XML_BASENAME).dll
XML_IMP = $(XML_BASENAME).lib
XML_A = $(XML_BASENAME).a

# Place where we let the compiler put its output.
BINDIR = bin.mingw
XML_INTDIR = int.mingw
XML_INTDIR_A = int.a.mingw
UTILS_INTDIR = int.utils.mingw

# The preprocessor and its options.
CPP = gcc.exe -E
CPPFLAGS += -I$(XML_SRCDIR)/include -DNOLIBTOOL 
ifeq ($(WITH_THREADS),1)
CPPFLAGS += -D_REENTRANT
endif

# The compiler and its options.
CC = gcc.exe
CFLAGS += -DWIN32 -D_WINDOWS -D_MBCS -DNOLIBTOOL 
CFLAGS += -I$(XML_SRCDIR) -I$(XML_SRCDIR)/include -I$(INCPREFIX) $(INCLUDE)
ifneq ($(WITH_THREADS),no)
CFLAGS += -D_REENTRANT
endif
ifeq ($(WITH_THREADS),yes) 
CFLAGS += -DHAVE_WIN32_THREADS -DHAVE_COMPILER_TLS
endif
ifeq ($(WITH_THREADS),ctls)
CFLAGS += -DHAVE_WIN32_THREADS -DHAVE_COMPILER_TLS
endif
ifeq ($(WITH_THREADS),native)
CFLAGS += -DHAVE_WIN32_THREADS
endif
ifeq ($(WITH_THREADS),posix)
CFLAGS += -DHAVE_PTHREAD_H
endif
ifeq ($(WITH_ZLIB),1)
CFLAGS += -DHAVE_ZLIB_H
endif
ifeq ($(WITH_LZMA),1)
CFLAGS += -DHAVE
Ubuntu下libxml2的交叉编译 2014-12-26 13:10 本站整理 浏览(587) Ubuntu下libxml2的交叉编译,有需要的朋友可以参考下。 环境为Ubuntu 14.04 LTS 64位 英文版本。 使用的交叉编译工具是arm-linux-gcc-4.3.2.tgz。 一、准备libxml2libxml2是一个跨平台的xml文件操作库。 项目地址:http://www.xmlsoft.org/ 我使用的是最新版本libxml2-2.9.2.tar.gz 、安装 我在在官网提供的网址https://git.gnome.org/browse/libxml2/上下载了几个版本的.tar.gz在Ubuntu下解压以后都没有看到configure文件,然后在ftp://xmlsoft.org/libxml2/下载的版本里却有configure文件……折腾一早上,简直坑爹,希望朋友们少走弯路…… 在解压文件夹下 rootroot@rootroot-virtual-machine:~/wyb$ cd libxml2-2.9.2/ rootroot@rootroot-virtual-machine:~/wyb/libxml2-2.9.2$ ./configure --prefix=/home/rootroot/wyb/libxml2-2.9.2/install CC=arm-linux-gcc LD=arm-linux-ld --enable-shared --enable-static --host=arm-linux --with-python=/home/rootroot/wyb/libxml2-2.9.2/python rootroot@rootroot-virtual-machine:~/wyb/libxml2-2.9.2$ make rootroot@rootroot-virtual-machine:~/wyb/libxml2-2.9.2$ make install 注意修改自己的交叉编译工具。如果不指定python路径(--with-python=/home/rootroot/wyb/libxml2-2.9.2/python),make之后会提示: rootroot@rootroot-virtual-machine:~/wyb/libxml2-2.9.2$ make make[4]: Entering directory `/home/rootroot/wyb/libxml2-2.9.2/python' CC libxml.lo cc1: warning: include location "/usr/include/python2.7" is unsafe for cross-compilation In file included from /usr/include/python2.7/Python.h:8, from libxml.c:14: /usr/include/python2.7/pyconfig.h:15:52: error: arm-linux-gnueabi/python2.7/pyconfig.h: No such file or directory In file included from /usr/include/python2.7/Python.h:77, from libxml.c:14: /usr/include/python2.7/pymath.h:18: warning: redundant redeclaration of 'copysign' /usr/include/python2.7/pymath.h:26: warning: redundant redeclaration of 'hypot' libxml.c: In function 'xmlPythonFileReadRaw': libxml.c:297: error: expected '(' before numeric constant libxml.c: In function 'xmlPythonFileRead': libxml.c:362: error: expected '(' before numeric constant make[4]: *** [libxml.lo] Error 1 make[4]: Leaving directory `/home/rootroot/wyb/libxml2-2.9.2/python' make[3]: *** [all-recursive] Error 1 make[3]: Leaving directory `/home/rootroot/wyb/libxml2-2.9.2/python' make[2]: *** [all] Error 2 make[2]: Leaving directory `/home/rootroot/wyb/libxml2-2.9.2/python' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/home/rootroot/wyb/libxml2-2.9.2' make: *** [all] Error 2 rootroot@rootroot-virtual-machine:~/wyb/libxml2-2.9.2$ 参考资料: http://blog.csdn.net/q1302182594/article/details/44975527 Linux中交叉编译libxml2 三、测试 随便找一个测试程序: // test.c #include #include #include int main(int argc, char **argv) { xmlDocPtr doc = NULL; xmlNodePtr root_node = NULL, node = NULL, node1 = NULL; doc = xmlNewDoc(BAD_CAST "1.0"); root_node = xmlNewNode(NULL, BAD_CAST "root"); xmlDocSetRootElement(doc, root_node); xmlNewChild(root_node, NULL, BAD_CAST "node1",BAD_CAST "content of node1"); node=xmlNewChild(root_node, NULL, BAD_CAST "node3",BAD_CAST"node has attributes"); xmlNewProp(node, BAD_CAST "attribute", BAD_CAST "yes"); node = xmlNewNode(NULL, BAD_CAST "node4"); node1 = xmlNewText(BAD_CAST"other way to create content"); xmlAddChild(node, node1); xmlAddChild(root_node, node); xmlSaveFormatFileEnc(argc > 1 ? argv[1] : "-", doc, "UTF-8", 1); xmlFreeDoc(doc); xmlCleanupParser(); xmlMemoryDump(); return(0); } 编译: rootroot@rootroot-virtual-machine:~/wyb$ arm-linux-gcc -I /home/rootroot/wyb/libxml2-2.9.2/install/include/libxml2 -L /home/rootroot/wyb/libxml2-2.9.2/install/lib -lxml2 test.c -o test rootroot@rootroot-virtual-machine:~/wyb$ file test test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped rootroot@rootroot-virtual-machine:~/wyb$
### 回答1: Libxml2是一个用于解析XML文档的开源软件库,它支持XML1.0、XML的命名空间、XML Schema以及XSLT等。在Libxml2中,sax1是一种基于事件的XML解析器,它可以逐个读取XML文档中的每个元素,并在解析时触发事件,从而达到解析XML文档的目的。 要编译sax1,请按照以下步骤操作: 1.在终端中打开libxml2的源代码地址。 2.使用命令./configure --with-sax1来启用sax1编译选项。这个命令将在编译时添加--with-sax1选项,以便将sax1解析器链接到libxml2库中。 3.执行make命令以编译libxml2。 4.执行make install命令以安装libxml2。 5.在你的应用程序中包含libxml2头文件,并连接到libxml2库,以便使用sax1解析器来解析你的XML文档。 需要注意的是,在使用sax1解析器时,你需要创建一个回调函数来处理解析事件。具体实现可以参考libxml2官方文档中的相关示例。同时,建议使用glib库来管理内存和错误处理,以避免内存泄漏和运行时错误。 ### 回答2: libxml2是一个XML C解析库,其中包含了各种所需的工具和函数。SAX(Simple API for XML)是一种解析XML的方法,基于解析器和事件驱动模型,适用于大型XML文档。对于某些应用程序来说,使用SAX可以比DOM(Document Object Model)更高效地解析XML文档。 要编译libxml2的SAX1模块,需要遵循以下步骤: 1. 确认安装了libxml2库及其开发文件(libxml2-dev或xml2-dev)。可以在终端中使用以下命令进行检查: ``` dpkg -s libxml2-dev ``` 2. 下载libxml2源代码,可以在http://xmlsoft.org/sources/ 找到最新的版本。 3. 解压缩源代码,进入源代码文件夹,使用以下命令进行编译: ``` ./configure --with-sax1 && make ``` --with-sax1选项告诉编译器要编译SAX1模块。make命令会编译源代码并生成库文件。 4. 如果编译成功,可以在源代码文件夹下的.slibs或.libs文件夹中找到生成的库文件。 5. 编写程序时需要引用libxml/parser.h头文件,并链接编译生成的库文件。使用SAX解析XML文件时需要注册解析器回调函数,并在解析时触发这些回调函数。 总的来说,编译libxml2的SAX1模块需要先确认安装了相关开发文件,然后通过配置选项告诉编译器要编译SAX1模块,最后生成库文件并在程序中引用。 ### 回答3: libxml2是一款开源的XML解析器,支持SAX和DOM两种解析方式。其中SAX解析方式是基于事件驱动的,需要用户自定义解析处理函数来响应不同的XML事件,适合解析大型XML文件和流式数据。 要编译libxml2的sax1模块,需要安装libxml2的开发包和sax1的头文件。在Linux系统中,可使用以下命令安装: sudo apt-get install libxml2-dev 安装后,进入libxml2源代码目录,运行以下命令: ./configure --with-sax1 make make install 其中,--with-sax1参数用于启用sax1模块,make命令用于编译,make install命令用于安装。 在编译过程中,可能会遇到一些依赖项缺失的错误,需要根据提示安装相应的依赖包。编译成功后,就可以在代码中使用sax1模块来解析XML数据了。 总之,编译libxml2的sax1模块需要安装开发包、头文件和依赖项,并使用特定的命令启用和编译sax1模块。对于熟悉Linux操作的开发者来说,这个过程并不复杂。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值