Re: [xml] compile libxml2.7.8 under cygwin&Win7 with mingw toolchain
- From: "lin hong" <lhong amnh org>
- To: xml gnome org
- Cc: xml gnome org
- Subject: Re: [xml] compile libxml2.7.8 under cygwin&Win7 with mingw toolchain
- Date: Tue, 6 Dec 2011 14:30:36 -0500 (EST)
lin hong wrote:
Hi, all
we are making a release of our software with libxml under windows. we
end
up compiling it from source code, I thought it might worth writing it
down
here.
first thing is, if you don't care about dependency of cygwin libraries
(which means the program require cygwin installed to run), just get
libxml
through cygwin setup. For us, it's not fair to ask normal user to
install
cygwin, so we try binary first.
I'm more comfortable with MSYS.
most work we did are under mac/linux, but for windows release, we are
using cygwin. is MSYS better than cygwin? I'm not familiar with windows at
all.
we got the binary from http://xmlsoft.org/sources/win32/
but it does not work on cygwin + Win7 , just try to run any exe file
under
/bin dir, we got this.
./xsltproc.exe
/usr/i686-pc-mingw32/xslt_xml2/bin/xsltproc.exe: error while loading
shared libraries: ?: cannot open shared object file: No such file or
directory
Where do the .dll live? In /usr/i686-pc-mingw32/xslt_xml2/bin? If not,
you'll need to add the path to the dll to PATH or move the dll to this
xslt_xml2/bin directory.
what ".dll" files do we need to move under /bin ?
I believe it works for WinXP because I saw the msg on the website:
"The binaries are supported on an operating system based on the
NT-kernel,
such as Windows NT, Windows 2000 and Windows XP, exclusively"
also it seems require iconv, which we don't really need.
libxslt requires it.
we did compile libxslt later without iconv -- at least I thought it works.
maybe we are missing some part of function.
anyway, we decide to compile it ourselves, here are the changes I did:
You'll need the patches I just submitted to this list.
0. for windows, makefile and configure are under /win32, run configure
like Readme.txt sugguests:
I believe you'll need to specify the --host switch if you're using Cygwin.
cscript configure.js threads:no static:yes compiler:mingw iconv:no
prefix=where_you_want_to_install include=where_your_mingw_include_is
lib=where_your_mingw_lib_is debug=yes
1. We are using mingw , so Makefile.mingw is the one for us. modify
Makefile.mingw:
With MSYS I just use configure to create the Makefile.
1.1 We want the program be independent from cygwin library, add
"-mno-cygwin" to CC
! CC = gcc.exe -mno-cygwin
The -mno-cygwin switch is dead. Cygwin now uses a cross build concept
instead of a bastardized separation of MinGW gcc and Cygwin gcc. This
is the reason you'll need to specify the --host if you Cygwin to
configure it.
really? we are using cygwin1.7.9(0.237/5/3). is the "--host" option for
cygwin or just for libxml?
if the "--host" option can take care of MingGW/Cygwin choice problem, it
would be great.
1.2 Want more output during compiling? add "-v"
! CFLAGS += -v -DWIN32 -D_WINDOWS -D_MBCS -DNOLIBTOOL
I don't know about these defines, I did not have to do that.
"-v" is just verbose option. it's not necessary. other options are default
by the makefile.
1.3 The default gcc linker refuse to look into Mingw directory before
Cygwin directory, I don't know why, so I use flexlink instead, modify
LD:
Again you need to add --host to the configure.
LD = flexlink
also add flags flexlink needs:
+ #flexlink flag
+ FL_LDFLAGS = -chain mingw
+ FL_LDFLAGS += -L $(BINDIR) -L $(LIBPREFIX)
I don't have any idea what flexlink is.
flexlink is linker that manage symbols for windows dll. make lift easier
for windows rookie like me, you can download it from
http://alain.frisch.fr/flexdll.html.
1.4 Then call our LD with its flags to make "dll"
# Creates the libxml shared object.
! #XMLSO_LDFLAGS = $(LDFLAGS) -shared -Wl,--dll
-Wl,--out-implib,$(BINDIR)/$(XML_IMP)
$(BINDIR)/$(XML_SO) : $(BINDIR) $(XML_OBJS)
! $(LD) $(FL_LDFLAGS) -o $(BINDIR)/$(XML_SO) $(XML_OBJS) $(LIBS)
Configure with --disable-static --enable-shared or vice versa.
I thought we need to set "static=1", so here we should do --enable-static
& --disable-shared?
1.5 Make ".a" , there is a typo in the original makefile, they mess up
the
"/" with "\" -- you will get a "bin.mingwlibxml2.a" instead of
"bin.mingw/libxml2.a" because of this.
# Creates the libxml archive.
$(BINDIR)/$(XML_A) : $(BINDIR) $(XML_OBJS_A)
! $(AR) $(ARFLAGS) $(BINDIR)/$(XML_A) $(XML_OBJS_A)
The Makefile.mingw is probably constructed to be used with mingw32-make
which can handle the \ in paths but lacks in other things.
where is "mingw32-make"?
1.6 Make sure STATIC is set to 1 in config.mingw -- if you did configure
with "static:yes", you are good. Add "-exe" to flexlink so it will
create
executable instead of dll file.
! # An implicit rule for xmllint and friends.
! # STATIC=1 is set in config.mingw
! # I also change XML_BASENAME to XML_NAME.(-llibxml2 to -lxml2)
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)
! $(LD) $(FL_LDFLAGS) -exe -o $@ $(subst .c,.o,$(UTILS_INTDIR)/$(<F))
-l$(XML_NAME) $(LIBS)
That's pretty much everything for makefile.
3. so far everything we did so far is under win32, config.h in the upper
dir needs to be changed
in config.h, find these two undef
/* Determine what socket length (socklen_t) data type is */
#undef XML_SOCKLEN_T
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
Define them
Without stdint.h you will get error message like "uint32 undefined".
4. set flag C_INCLUDE_PATH.
Set c_include_path flag can fix the "could not find libxml/xxx.h"
problem
Head files are under /libxml2-2.7.8/include and
/libxml2-2.7.8/include/libxml/,
to make our gcc look into these directories, we need to point
C_INCLUDE_PATH to them, just setting C_FLAGS is NOT enough -- that's
really really strange.
although later I found out /libxml2-2.7.8/libxml/ also have a set of all
head files, so maybe pointing C_INCLUDE_PATH to that is also ok.
OK, take a breath and run
make -f Makefile.mingw
that's it.
Without my patch xmlcatalog will fail to read the entries in the catalog
if you use GCC-4.6.1.
All I needed to do with MinGW + MSYS otherwise was
cd libxml2-2.7.8
mkdir bld
cd bld
../configure --prefix=/mingw --without-python --enable-shared
--disable-static
make
make install
I've also built it with the python bindings but you must ensure that
your environment is set up with PYTHON variables.
--
Earnie
-- https://sites.google.com/site/earnieboyd/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]