[xml] compile libxml2.7.8 under cygwin&Win7 with mingw toolchain



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.

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

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.

anyway, we decide to compile it ourselves,  here are the changes I did:

0. for windows, makefile and configure are under /win32, run configure
like Readme.txt sugguests:

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:

1.1 We want the program be independent from cygwin library, add
"-mno-cygwin" to CC
! CC = gcc.exe -mno-cygwin

1.2 Want more output during compiling? add "-v"
! CFLAGS += -v -DWIN32 -D_WINDOWS -D_MBCS -DNOLIBTOOL

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:
LD = flexlink
also add flags flexlink needs:
+ #flexlink flag
+ FL_LDFLAGS = -chain mingw
+ FL_LDFLAGS += -L $(BINDIR) -L $(LIBPREFIX)

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)

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)

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.



--
Best.
Lin Hong
Division of Invertebrate Zoology
American Museum of Natural History
Tel: 212-313-7581
POY website : http://research.amnh.org/scicomp/scripts/download.php






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]