作者: TAMURA.KENICHI
日時: 2002/1/28(01:53)
たむらです。

実は結構前に対応できたのですが、表に出すタイミングが…
Perl/Python/Ruby などの parser から利用されるケースの多い expat の
 cygwin 上でのビルドについてのメモです。
ついでに、 Perl の RSS モジュールまで

ちなみに、参照情報。
Python, Perl or Ruby for XML?
<URL:http://www.yoshidam.net/PythonPerlRuby.html>

魅力的なPython: Python用XMLツールの再考 - ツールとコードに関する最新情報
<URL:http://www-6.ibm.com/jp/developerworks/linux/010824/j_l-pxml.html>

IBM developerWorks <URL:http://www-6.ibm.com/jp/developerworks/>
は、XML向けのドキュメントもたくさん。

XML文書をPerlなどのスクリプト言語で処理する
<URL:http://www.jp.ibm.com/developerworks/xml/xml-perl.html>
Perl と XML のどこが悪いというのでしょうか ?
<URL:http://www.janit.com/netbranch/Perl/XMLPerl/XMLPerl20001011.html>
XMLリソース
C-STATION
<URL:http://www.horae.dti.ne.jp/~tkimata/cgi/reference/Perl.htm>

[expat]
$ ( ./configure && make) >& build.log
creating cache ./config.cache
checking host system type... i686-pc-cygwin
checking build system type... i686-pc-cygwin
checking for ranlib... ranlib
checking for gcc... gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
checking for ld used by GCC... /usr/i686-pc-cygwin/bin/ld.exe
checking if the linker (/usr/i686-pc-cygwin/bin/ld.exe) is GNU ld... yes
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking for dlltool... dlltool
checking for as... as
checking for objdump... objdump
updating cache ./config.cache
checking for object suffix... o
checking for executable suffix... .exe
checking for gcc option to produce PIC... none
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.lo... yes
checking if gcc supports -fno-rtti -fno-exceptions ... yes
checking if gcc static flag -static works... -static
checking if the linker (/usr/i686-pc-cygwin/bin/ld.exe) is GNU ld... yes
checking whether the linker (/usr/i686-pc-cygwin/bin/ld.exe) supports shared libraries... yes
checking command to parse /usr/bin/nm -B output... ok
checking how to hardcode library paths into programs... immediate
checking for /usr/i686-pc-cygwin/bin/ld.exe option to reload object files... -r
checking dynamic linker characteristics... Win32 ld.exe
checking if libtool supports shared libraries... yes
checking if package supports dlls... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for objdir... .libs
creating libtool
loading cache ./config.cache
checking for gcc... (cached) gcc
checking whether the C compiler (gcc -g -O2 ) works... yes
checking whether the C compiler (gcc -g -O2 ) is a cross-compiler... no
checking whether we are using GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for a BSD compatible install... /usr/bin/install -c
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for fcntl.h... yes
checking for unistd.h... yes
checking whether byte ordering is bigendian... no
checking for working const... yes
checking for off_t... yes
checking for size_t... yes
checking for 8-bit clean memcmp... yes
checking for unistd.h... (cached) yes
checking for getpagesize... yes
checking for working mmap... no
checking for memmove... yes
checking for bcopy... yes
updating cache ./config.cache
creating ./config.status
creating Makefile
creating lib/Makefile
creating lib/expat.h
creating xmlwf/Makefile
creating examples/Makefile
creating config.h
cd lib && make
make[1]: Entering directory `/home/tamura/src/CYGWIN/pe/expat-1.95.2/lib'
/bin/sh ../libtool --mode=compile gcc -DHAVE_CONFIG_H -DPACKAGE='"expat"' -DVERSION='"expat_1.95.2"' -I. -I. -I..  -g -O2 -Wall -Wmissing-prototypes 

 : snip

(cd .libs && rm -f libexpat.la && ln -s ../libexpat.la libexpat.la)
make[1]: Leaving directory `/home/tamura/src/CYGWIN/pe/expat-1.95.2/lib'
cd xmlwf && make
make[1]: Entering directory `/home/tamura/src/CYGWIN/pe/expat-1.95.2/xmlwf'
gcc -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -I../lib   -c -o xmlwf.o xmlwf.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -I../lib   -c -o xmlfile.o xmlfile.c
xmlfile.c: In function `processStream':
xmlfile.c:149: warning: implicit declaration of function `close'
xmlfile.c:153: warning: implicit declaration of function `read'
gcc -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -I../lib   -c -o codepage.o codepage.c
gcc -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -I../lib   -c -o unixfilemap.o unixfilemap.c
gcc -o xmlwf -static xmlwf.o xmlfile.o codepage.o unixfilemap.o -L../lib/.libs -lexpat
xmlwf.o: In function `defaultCharacterData':
/home/tamura/src/CYGWIN/pe/expat-1.95.2/xmlwf/xmlwf.c:239: undefined reference to `_imp__XML_DefaultCurrent'

 : snip

collect2: ld returned 1 exit status
make[1]: *** [xmlwf] Error 1
make[1]: Leaving directory `/home/tamura/src/CYGWIN/pe/expat-1.95.2/xmlwf'
make: *** [xmlwf] Error 2

libexpat.a とリンクするところで、referenceがないのエラーが大量に。
単純にエントリポイントがないって感じ。
Google.com で Cygwin expat で検索
http://www.google.com/search?q=cache:VGjOOe8R6N4C:mail.python.org/pipermail/python-list/2001-September/064426.html+expat+cygwin&hl=ja

expat.h の最初の方の、
#ifndef XMLPARSEAPI
#  if defined(__declspec) && !defined(__BEOS__)
#    define XMLPARSEAPI(type) __declspec(dllimport) type __cdecl
#  else
#    define XMLPARSEAPI(type) type
#  endif
#endif  /* not defined XMLPARSEAPI */

を

#  if defined(__declspec) && !defined(__BEOS__) && !defined(__CYGWIN__)

のように、『__CYGWIN__』のケースを追加する。

無事できるので、make install

ちなみに、1.95.1の時は、
#ifndef XMLPARSEAPI
#  ifdef __declspec
#    define XMLPARSEAPI __declspec(dllimport)
#  else
#    define XMLPARSEAPI /* nothing */
#  endif
#endif  /* not defined XMLPARSEAPI */

だったので、問題なかった。
if defined(__declspec) && defined(__BEOS__) と
else にすればいいだろうに。深く考えてないけど (^^

ついでに言うと、bmingw でビルドできないし。

gcc -bmingw -Os -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -I../lib
  -c -o unixfilemap.o unixfilemap.c
unixfilemap.c:7: sys/mman.h: No such file or directory
make[1]: *** [unixfilemap.o] Error 1
make[1]: Leaving directory `/home/tamura/src/MINGW/expat-1.95.2/xmlwf'
make: *** [xmlwf] Error 2

# やっぱ mmap関連か… 1.95.1 にしとけって


[XML::Parse]

perl Makefile.PL の時にexpatの位置のパラメータを渡す。

$ perl Makefile.PL EXPATLIBPATH=/usr/local/lib EXPATINCPATH=/usr/local/include
$ make
$ make test
$ make install

$ cd ../XML-Parser-2.30/
$ perl Makefile.PL

Expat must be installed prior to building XML::Parser and I can't find
it in the standard library directories. You can download expat from:

http://sourceforge.net/projects/expat/

If expat is installed, but in a non-standard directory, then use the
following options to Makefile.PL:

    EXPATLIBPATH=...  To set the directory in which to find libexpat

    EXPATINCPATH=...  To set the directory in which to find expat.h

For example:

    perl Makefile.PL EXPATLIBPATH=/home/me/lib EXPATINCPATH=/home/me/include

Note that if you build against a shareable library in a non-standard location
you may (on some platforms) also have to set your LD_LIBRARY_PATH environment
variable at run time for perl to find the library.

$ perl Makefile.PL EXPATLIBPATH=/usr/local/lib EXPATINCPATH=/usr/local/include
Checking if your kit is complete...
Looks good
Writing Makefile for XML::Parser::Expat
Writing Makefile for XML::Parser

$ make
cp Parser/Encodings/README blib/lib/XML/Parser/Encodings/README
cp Parser/Encodings/iso-8859-7.enc blib/lib/XML/Parser/Encodings/iso-8859-7.enc
cp Parser/Encodings/x-sjis-cp932.enc blib/lib/XML/Parser/Encodings/x-sjis-cp932.enc
cp Parser/Encodings/big5.enc blib/lib/XML/Parser/Encodings/big5.enc
cp Parser/Encodings/windows-1250.enc blib/lib/XML/Parser/Encodings/windows-1250.enc
cp Parser/Encodings/iso-8859-8.enc blib/lib/XML/Parser/Encodings/iso-8859-8.enc
cp Parser/Encodings/iso-8859-2.enc blib/lib/XML/Parser/Encodings/iso-8859-2.enc
cp Parser/Encodings/x-euc-jp-jisx0221.enc blib/lib/XML/Parser/Encodings/x-euc-jp-jisx
0221.enc
cp Parser/Encodings/iso-8859-9.enc blib/lib/XML/Parser/Encodings/iso-8859-9.enc
cp Parser/Encodings/x-sjis-unicode.enc blib/lib/XML/Parser/Encodings/x-sjis-unicode.e
nc
cp Parser/Encodings/iso-8859-3.enc blib/lib/XML/Parser/Encodings/iso-8859-3.enc
cp Parser/Encodings/x-sjis-jdk117.enc blib/lib/XML/Parser/Encodings/x-sjis-jdk117.enc
cp Parser/Encodings/euc-kr.enc blib/lib/XML/Parser/Encodings/euc-kr.enc
cp Parser/Encodings/iso-8859-4.enc blib/lib/XML/Parser/Encodings/iso-8859-4.enc
cp Parser/Encodings/Japanese_Encodings.msg blib/lib/XML/Parser/Encodings/Japanese_Enc
odings.msg
cp Parser/Encodings/x-sjis-jisx0221.enc blib/lib/XML/Parser/Encodings/x-sjis-jisx0221
.enc
cp Parser.pm blib/lib/XML/Parser.pm
cp Parser/Encodings/iso-8859-5.enc blib/lib/XML/Parser/Encodings/iso-8859-5.enc
cp Parser/Encodings/x-euc-jp-unicode.enc blib/lib/XML/Parser/Encodings/x-euc-jp-unico
de.enc
cp Parser/LWPExternEnt.pl blib/lib/XML/Parser/LWPExternEnt.pl
make[1]: Entering directory `/home/tamura/src/CYGWIN/XML-Parser-2.30/Expat'
cp Expat.pm ../blib/lib/XML/Parser/Expat.pm
/usr/bin/perl -I/usr/lib/perl5/5.6.1/cygwin-multi -I/usr/lib/perl5/5.6.1 /usr/lib/per
l5/5.6.1/ExtUtils/xsubpp -noprototypes -typemap /usr/lib/perl5/5.6.1/ExtUtils/typemap
 -typemap typemap Expat.xs > Expat.xsc && mv Expat.xsc Expat.c
gcc -c -I/usr/local/include -DPERL_USE_SAFE_PUTENV -fno-strict-aliasing -I/usr/local/
include -DUSEIMPORTLIB -O2   -DVERSION=\"2.30\" -DXS_VERSION=\"2.30\"  -I/usr/lib/per
l5/5.6.1/cygwin-multi/CORE  Expat.c
Running Mkbootstrap for XML::Parser::Expat ()
chmod 644 Expat.bs
rm -f ../blib/arch/auto/XML/Parser/Expat/Expat.dll
LD_RUN_PATH="/usr/local/lib" ld2  -s -L/usr/local/lib Expat.o  -o ../blib/arch/auto/X
ML/Parser/Expat/Expat.dll  /usr/lib/perl5/5.6.1/cygwin-multi/CORE/libperl5_6_1.a -L/u
sr/local/lib -lexpat
dllwrap --dllname Expat.dll --driver-name gcc --dlltool dlltool --export-all-symbols
--as as --output-def libExpat.def --output-lib libExpat.a \
-s -L/usr/local/lib Expat.o  /usr/lib/perl5/5.6.1/cygwin-multi/CORE/libperl5_6_1.a -L
/usr/local/lib -lexpat
dllwrap: no export definition file provided
dllwrap: creating one, but that may not be what you want
mv Expat.dll libExpat.a ../blib/arch/auto/XML/Parser/Expat/
chmod 755 ../blib/arch/auto/XML/Parser/Expat/Expat.dll
cp Expat.bs ../blib/arch/auto/XML/Parser/Expat/Expat.bs
chmod 644 ../blib/arch/auto/XML/Parser/Expat/Expat.bs
Manifying ../blib/man3/XML.Parser.Expat.3
make[1]: Leaving directory `/home/tamura/src/CYGWIN/XML-Parser-2.30/Expat'
Manifying blib/man3/XML.Parser.3

$ make test
make[1]: Entering directory `/home/tamura/src/CYGWIN/XML-Parser-2.30/Expat'
make[1]: Leaving directory `/home/tamura/src/CYGWIN/XML-Parser-2.30/Expat'
PERL_DL_NONLAZY=1 /usr/bin/perl -Iblib/arch -Iblib/lib -I/usr/lib/perl5/5.6.1/cygwin-
multi -I/usr/lib/perl5/5.6.1 -e 'use Test::Harness qw(&runtests $verbose); $verbose=0
; runtests @ARGV;' t/*.t
t/astress...........ok
t/cdata.............ok
t/decl..............ok
t/defaulted.........ok
t/encoding..........ok
t/external_ent......Couldn't load LWP based external entity handler
Switching to file-based external entity handler
 (To avoid this message, use NoLWP option to XML::Parser)
t/external_ent......ok
t/file..............ok
t/finish............ok
t/namespaces........ok
t/parament..........Couldn't load LWP based external entity handler
Switching to file-based external entity handler
 (To avoid this message, use NoLWP option to XML::Parser)
t/parament..........ok
t/partial...........ok
t/skip..............ok
t/stream............ok
All tests successful.
Files=13, Tests=113,  3 wallclock secs ( 2.33 cusr +  1.27 csys =  3.60 CPU)

$ make install
make[1]: Entering directory `/home/tamura/src/CYGWIN/XML-Parser-2.30/Expat'
make[1]: Leaving directory `/home/tamura/src/CYGWIN/XML-Parser-2.30/Expat'
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/auto/XML/Parser/Expat/Expat.bs
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/auto/XML/Parser/Expat/Expat.dl
l
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/auto/XML/Parser/Expat/libExpat
.a
Files found in blib/arch: installing files in blib/lib into architecture dependent li
brary tree
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser.pm
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Expat.pm
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/LWPExternEnt.pl
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/big5.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/euc-kr.en
c
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/iso-8859-
2.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/iso-8859-
3.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/iso-8859-
4.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/iso-8859-
5.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/iso-8859-
7.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/iso-8859-
8.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/iso-8859-
9.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/Japanese_
Encodings.msg
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/README
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/windows-1
250.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/x-euc-jp-
jisx0221.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/x-euc-jp-
unicode.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/x-sjis-cp
932.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/x-sjis-jd
k117.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/x-sjis-ji
sx0221.enc
Installing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/XML/Parser/Encodings/x-sjis-un
icode.enc
Installing /usr/man/man3/XML.Parser.3
Installing /usr/man/man3/XML.Parser.Expat.3
Writing /usr/lib/perl5/site_perl/5.6.1/cygwin-multi/auto/XML/Parser/.packlist
Appending installation info to /usr/lib/perl5/5.6.1/cygwin-multi/perllocal.pod

[XML::RSS]
ちっとも問題なし
$ perl Makefile.PL && make
$ make test
$ make install

後は使うだけ ?


日記はじめました。 http://slashdot.jp/journal.pl?op=display&uid=4115
たむら mailto:sgs02516@...