坑爹的libxml2 for mingw 编译 (二)

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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_LZMA_H
endif

# The linker and its options.
LD = gcc.exe
LDFLAGS += -Wl,--major-image-version,$(LIBXML_MAJOR_VERSION)
LDFLAGS += -Wl,--minor-image-version,$(LIBXML_MINOR_VERSION)
LDFLAGS += -Wl,-L,$(BINDIR) -Wl,-L,$(LIBPREFIX)
LIBS =
ifeq ($(WITH_FTP),1)
CFLAGS += -D_WINSOCKAPI_
LIBS += -lwsock32 -lws2_32
endif 
ifeq ($(WITH_HTTP),1)
CFLAGS += -D_WINSOCKAPI_
LIBS += -lwsock32 -lws2_32
endif 
ifeq ($(WITH_ICONV),1)
LIBS += -liconv
endif 
ifeq ($(WITH_ZLIB),1)
# Could be named differently
# LIBS += -lzdll
LIBS += -lz
endif
ifeq ($(WITH_LZMA),1)
LIBS += -llzma
endif
ifeq ($(WITH_THREADS),posix)
LIBS += -lpthreadGC
endif
ifeq ($(WITH_MODULES),1)
LIBS += -lkernel32
endif

LIBS += $(LIB)

# The archiver and its options.
AR = ar.exe
ARFLAGS = -r

# Optimisation and debug symbols.
ifeq ($(DEBUG),1)
CFLAGS += -D_DEBUG -g
LDFLAGS += 
else
CFLAGS += -DNDEBUG -O2 
LDFLAGS += 
endif


# Libxml object files.
XML_OBJS = $(XML_INTDIR)/buf.o\
	$(XML_INTDIR)/c14n.o\
	$(XML_INTDIR)/catalog.o\
	$(XML_INTDIR)/chvalid.o\
	$(XML_INTDIR)/debugXML.o\
	$(XML_INTDIR)/dict.o\
	$(XML_INTDIR)/DOCBparser.o\
	$(XML_INTDIR)/encoding.o\
	$(XML_INTDIR)/entities.o\
	$(XML_INTDIR)/error.o\
	$(XML_INTDIR)/globals.o\
	$(XML_INTDIR)/hash.o\
	$(XML_INTDIR)/HTMLparser.o\
	$(XML_INTDIR)/HTMLtree.o\
	$(XML_INTDIR)/legacy.o\
	$(XML_INTDIR)/list.o\
	$(XML_INTDIR)/nanoftp.o\
	$(XML_INTDIR)/nanohttp.o\
	$(XML_INTDIR)/parser.o\
	$(XML_INTDIR)/parserInternals.o\
	$(XML_INTDIR)/pattern.o\
	$(XML_INTDIR)/relaxng.o\
	$(XML_INTDIR)/SAX.o\
	$(XML_INTDIR)/SAX2.o\
	$(XML_INTDIR)/schematron.o\
	$(XML_INTDIR)/threads.o\
	$(XML_INTDIR)/tree.o\
	$(XML_INTDIR)/uri.o\
	$(XML_INTDIR)/valid.o\
	$(XML_INTDIR)/xinclude.o\
	$(XML_INTDIR)/xlink.o\
	$(XML_INTDIR)/xmlIO.o\
	$(XML_INTDIR)/xmlmemory.o\
	$(XML_INTDIR)/xmlreader.o\
	$(XML_INTDIR)/xmlregexp.o\
	$(XML_INTDIR)/xmlmodule.o\
	$(XML_INTDIR)/xmlsave.o\
	$(XML_INTDIR)/xmlschemas.o\
	$(XML_INTDIR)/xmlschemastypes.o\
	$(XML_INTDIR)/xmlunicode.o\
	$(XML_INTDIR)/xmlwriter.o\
	$(XML_INTDIR)/xpath.o\
	$(XML_INTDIR)/xpointer.o\
	$(XML_INTDIR)/xmlstring.o

XML_SRCS = $(subst .o,.c,$(subst $(XML_INTDIR)/,$(XML_SRCDIR)/,$(XML_OBJS)))

# Static libxml object files.
XML_OBJS_A = $(XML_INTDIR_A)/buf.o\
	$(XML_INTDIR_A)/c14n.o\
	$(XML_INTDIR_A)/catalog.o\
	$(XML_INTDIR_A)/chvalid.o\
	$(XML_INTDIR_A)/debugXML.o\
	$(XML_INTDIR_A)/dict.o\
	$(XML_INTDIR_A)/DOCBparser.o\
	$(XML_INTDIR_A)/encoding.o\
	$(XML_INTDIR_A)/entities.o\
	$(XML_INTDIR_A)/error.o\
	$(XML_INTDIR_A)/globals.o\
	$(XML_INTDIR_A)/hash.o\
	$(XML_INTDIR_A)/HTMLparser.o\
	$(XML_INTDIR_A)/HTMLtree.o\
	$(XML_INTDIR_A)/legacy.o\
	$(XML_INTDIR_A)/list.o\
	$(XML_INTDIR_A)/nanoftp.o\
	$(XML_INTDIR_A)/nanohttp.o\
	$(XML_INTDIR_A)/parser.o\
	$(XML_INTDIR_A)/parserInternals.o\
	$(XML_INTDIR_A)/pattern.o\
	$(XML_INTDIR_A)/relaxng.o\
	$(XML_INTDIR_A)/SAX.o\
	$(XML_INTDIR_A)/SAX2.o\
	$(XML_INTDIR_A)/schematron.o\
	$(XML_INTDIR_A)/threads.o\
	$(XML_INTDIR_A)/tree.o\
	$(XML_INTDIR_A)/uri.o\
	$(XML_INTDIR_A)/valid.o\
	$(XML_INTDIR_A)/xinclude.o\
	$(XML_INTDIR_A)/xlink.o\
	$(XML_INTDIR_A)/xmlIO.o\
	$(XML_INTDIR_A)/xmlmemory.o\
	$(XML_INTDIR_A)/xmlreader.o\
	$(XML_INTDIR_A)/xmlregexp.o\
	$(XML_INTDIR_A)/xmlmodule.o\
	$(XML_INTDIR_A)/xmlsave.o\
	$(XML_INTDIR_A)/xmlschemas.o\
	$(XML_INTDIR_A)/xmlschemastypes.o\
	$(XML_INTDIR_A)/xmlunicode.o\
	$(XML_INTDIR_A)/xmlwriter.o\
	$(XML_INTDIR_A)/xpath.o\
	$(XML_INTDIR_A)/xpointer.o\
	$(XML_INTDIR_A)/xmlstring.o

XML_SRCS_A = $(subst .o,.c,$(subst $(XML_INTDIR_A)/,$(XML_SRCDIR)/,$(XML_OBJS_A)))

# Xmllint and friends executables.
UTILS = $(BINDIR)/xmllint.exe\
	$(BINDIR)/xmlcatalog.exe\
	$(BINDIR)/testAutomata.exe\
	$(BINDIR)/testC14N.exe\
	$(BINDIR)/testDocbook.exe\
	$(BINDIR)/testHTML.exe\
	$(BINDIR)/testReader.exe\
	$(BINDIR)/testRegexp.exe\
	$(BINDIR)/testModule.exe\
	$(BINDIR)/testRelax.exe\
	$(BINDIR)/testSAX.exe\
	$(BINDIR)/testSchemas.exe\
	$(BINDIR)/testURI.exe\
	$(BINDIR)/testXPath.exe\
	$(BINDIR)/runtest.exe\
	$(BINDIR)/runsuite.exe\
	$(BINDIR)/testapi.exe\
	$(BINDIR)/testlimits.exe

ifeq ($(WITH_THREADS),yes)
UTILS += $(BINDIR)/testThreadsWin32.exe
endif
ifeq ($(WITH_THREADS),ctls) 
UTILS += $(BINDIR)/testThreadsWin32.exe
endif
ifeq ($(WITH_THREADS),native)
UTILS += $(BINDIR)/testThreadsWin32.exe
endif
ifeq ($(WITH_THREADS),posix)
UTILS += $(BINDIR)/testThreads.exe
endif

all : dep libxml libxmla utils

libxml : $(BINDIR)/$(XML_SO) 

libxmla : $(BINDIR)/$(XML_A)

utils : $(UTILS)

clean :
	cmd.exe /C "if exist $(XML_INTDIR) rmdir /S /Q $(XML_INTDIR)"
	cmd.exe /C "if exist $(XML_INTDIR_A) rmdir /S /Q $(XML_INTDIR_A)"
	cmd.exe /C "if exist $(UTILS_INTDIR) rmdir /S /Q $(UTILS_INTDIR)"
	cmd.exe /C "if exist $(BINDIR) rmdir /S /Q $(BINDIR)"
	cmd.exe /C "if exist depends.mingw del depends.mingw"

distclean : clean
	cmd.exe /C "if exist config.* del config.*"
	cmd.exe /C "if exist Makefile del Makefile"

rebuild : clean all

install-libs : all
	mkdir -p $(INCPREFIX)\libxml2
	mkdir -p $(INCPREFIX)\libxml2\libxml
	mkdir -p $(BINPREFIX)
	mkdir -p $(LIBPREFIX)
	cp -p /usr/home/Weiny/libxml2-2.9.1/include/libxml/*.h $(INCPREFIX)/libxml2/libxml/
	cp -p $(BINDIR)/$(XML_SO) $(SOPREFIX)/
	cp -p $(BINDIR)/$(XML_A) $(LIBPREFIX)/
	cp -p $(BINDIR)/$(XML_IMP) $(LIBPREFIX)/
	cp -p $(BINDIR)/xml*.exe $(BINPREFIX)/

install : install-libs
	cp -p $(BINDIR)/*.exe $(BINPREFIX)/

install-dist : install-libs
	cp -p $(BINDIR)/xml*.exe $(BINPREFIX)/

# This is a target for me, to make a binary distribution. Not for the public use,
# keep your hands off :-)
BDVERSION = $(LIBXML_MAJOR_VERSION).$(LIBXML_MINOR_VERSION).$(LIBXML_MICRO_VERSION)
BDPREFIX = $(XML_BASENAME)-$(BDVERSION).win32
bindist : all
	$(MAKE) PREFIX=$(BDPREFIX) SOPREFIX=$(BDPREFIX)/bin install-dist
	cscript //NoLogo configure.js genreadme $(XML_BASENAME) $(BDVERSION) $(BDPREFIX)\readme.txt


# Creates the dependency file
dep :
	$(CC) $(CFLAGS) -M $(XML_SRCS) > depends.mingw


# Makes the output directory.
$(BINDIR) :
	mkdir -p $(BINDIR)


# Makes the libxml intermediate directory.
$(XML_INTDIR) :
	mkdir -p $(XML_INTDIR)

# Makes the static libxml intermediate directory.
$(XML_INTDIR_A) :
	mkdir -p $(XML_INTDIR_A)

# An implicit rule for libxml compilation.
$(XML_INTDIR)/%.o : $(XML_SRCDIR)/%.c
	$(CC) $(CFLAGS) -o $@ -c $<

# An implicit rule for static libxml compilation.
$(XML_INTDIR_A)/%.o : $(XML_SRCDIR)/%.c
	$(CC) $(CFLAGS) -DLIBXML_STATIC -o $@ -c $<


# Compiles libxml source. Uses the implicit rule for commands.
$(XML_OBJS) : $(XML_INTDIR)

# Compiles static libxml source. Uses the implicit rule for commands.
$(XML_OBJS_A) : $(XML_INTDIR_A) 

# Creates the libxml shared object.
XMLSO_LDFLAGS = $(LDFLAGS) -shared -Wl,--dll -Wl,--out-implib,$(BINDIR)/$(XML_IMP)
$(BINDIR)/$(XML_SO) : $(BINDIR) $(XML_OBJS)
	$(LD) $(XMLSO_LDFLAGS) -o $(BINDIR)/$(XML_SO) $(XML_OBJS) $(LIBS)

# Creates the libxml archive.
$(BINDIR)/$(XML_A) : $(BINDIR) $(XML_OBJS_A)
	$(AR) $(ARFLAGS) $(BINDIR)\$(XML_A) $(XML_OBJS_A)


# Makes the utils intermediate directory.
$(UTILS_INTDIR) :
	mkdir -p mkdir $(UTILS_INTDIR)

# An implicit rule for xmllint and friends.
ifeq ($(STATIC),1)
$(BINDIR)/%.exe : $(UTILS_SRCDIR)/%.c
	$(CC) -DLIBXML_STATIC $(CFLAGS) -o $(subst .c,.o,$(UTILS_INTDIR)/$(<F)) -c $< 
	$(LD) $(LDFLAGS) -o $@ $(subst .c,.o,$(UTILS_INTDIR)/$(<F)) -l$(XML_BASENAME) $(LIBS) 
else
$(BINDIR)/%.exe : $(UTILS_SRCDIR)/%.c
	$(CC) $(CFLAGS) -o $(subst .c,.o,$(UTILS_INTDIR)/$(<F)) -c $< 
	$(LD) $(LDFLAGS) -o $@ $(subst .c,.o,$(UTILS_INTDIR)/$(<F)) -l$(XML_BASENAME) $(LIBS) 
endif

# Builds xmllint and friends. Uses the implicit rule for commands.
$(UTILS) : $(UTILS_INTDIR) $(BINDIR) libxml libxmla

# Source dependencies
#-include depends.mingw

联系方式:weinyzhou86@gmail.com

QQ:514540005

版权所有,禁止转载.

发布自:http://blog.youkuaiyun.com/weinyzhou/article/details/9468061



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.youkuaiyun.com/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$
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值