Apache Xerces-C++ の古いバージョンの置き場所 http://archive.apache.org/dist/xml/xerces-c/ から xerces-c-src_2_7_0.tar.gz をダウンロードして

Cygwin 上にて、


$ tar zxvf ./xerces-c-src_2_7_0.tar.gz
$ cd xerces-c-src_2_7_0/src/xercesc
$ export XERCESCROOT=/home/hoge/xerces-c-src_2_7_0
$ ./runConfigure -pcygwin -cgcc -xg++
$ make

とやってビルド完了。

XERCESCROOT のパスを間違えるとビルドにも失敗するので要注意 (このミス何度もやってる・・・)。

xerces-c-src_2_7_0/lib にライブラリファイル、 xerces-c-src_2_7_0/include にインクルード用のヘッダファイルが入っている。

ちなみに、ビルドに使った gcc は gcc 3.4.4

同梱されているドキュメントには "Building Xerces-C++ on Windows using Cygwin" というタイトルでビルドについての情報が以下のように載っている。

Xerces-C++ may be built in the Cygwin environment for use by Cygwin applications. As with the UNIX platforms, Xerces-C++ on Cygwin uses GNU tools. Therefore, with a couple of notable exceptions, Xerces-C++ on Cygwin is built using the same instructions as the UNIX platforms. The build environment variable XERCESCROOT must be set to the proper path containing the Xerces-C++ sources and runConfigure must be run with the "-pcygwin -cgcc -xg++" arguments.

Note that Cygwin is different from the UNIX platforms in the way that it finds libraries at run time. While UNIX platforms may use the environment variable LD_LIBRARY_PATH, Cygwin uses the PATH environment variable.

There is an issue with the gcc/g++ compiler version 2.95, where C++ exceptions thrown from a dll will cause the application to crash, regardless of whether there is a "catch" statement. This bug doesn't occur in tests using gcc 3.1 or 3.2, so it is recommended that you use gcc 3.1 or higher.

Ref. Xerces-C++ XML Parser

追記: 2011-12-07

実行時に "error while loading shared libraries: cygxerces-c27.dll: cannot open shared object file: No such file or directory" なんてエラーが出てしまった。

なお、一般の UNIX 系 OS では共有ライブラリ(.soなど)は /lib や /usr/lib に格納されます。しかし Windows では実行パス中に置かれていない DLL は利用できませんので、Cygwin では /bin のような、実行パスが通された位置に DLL が格納されています。

/bin と /usr/bin が同一なのはなぜか

たしかに、 Cygwin の /bin ディレクトリにはいろいろなライブラリのDLLファイルが置いてあった。
なので、 /bin に cygxerces-c27.dll などの DLL を置いて実行したらエラーがなくなってちゃんと動いてくれた。

tags: xerces c++ cygwin

Posted by NI-Lab. (@nilab)