Introduction

This guide shows how to build statically-linked Win32 XSD compiler with GCC-Mingw toolchain using the Cygwin environment. The resulting binary is supposed to be self-sufficient and can be used on other Win32 machines without installing Cygwin or copying any DLLs. The generated code can be compiled with other C++ compiler (e.g., Visual C++). The XSD runtime is a header-only library and does not need to be built. If you run into problems while following these instructions feel free to ask for help on the xsd-users mailing list.

Unfortunately, the stock libstdc++ (Standard C++ Library, part of g++) that comes with the Cygwin/Mingw environment is compiled without support for wchar_t. You can read more about this on the Mingw website. As a result, we will be using STLPort instead of libstdc++.

The build commands presented below assume that you download and build source code in your home directory. Adjust your paths accordingly if you are using a different directory.

Cygwin

Download Cygwin from the Cygwin website. When installing, make sure the following packages are selected:

Devel/gcc
Devel/gcc-core
Devel/gcc-g++          (3.4.4 or later)
Devel/gcc-mingw-core
Devel/gcc-mingw-g++    (3.4.4 or later)
Devel/make

Interpreters/m4

Shells/bash

Util/bzip2
  

GNU make

Check the version of GNU make that comes with Cygwin by executing make --version. If the version is lower than 3.81, download GNU make 3.81 or later from the GNU make website. Then follow these build and installation instructions:

$ cd
$ bzip -dc make-3.81.tar.bz2 | tar x
$ cd make-3.81
$ ./configure
$ make
$ make install
$ make --version
GNU Make 3.81
  

Build

Download the latest build source release from the build website. Then follow these installation instructions:

$ cd
$ bzip2 -dc build-0.2.2.tar.bz2 | tar x
$ cd build-0.2.2
$ make install install_prefix=/usr/local
  

Note that you need to install build in a location where GNU make looks for included makefiles by default (normally /usr/include and /usr/local/include). Otherwise you will need to add the build include directory to the make search list. For example, if you installed build to /home/user/install, then the following command will add the include directory in this path to the make search list:

$ export MAKEFLAGS=-I/home/user/install/include
  

STLPort

Download the latest STLPort source release from the STLPort website. Then follow these build instructions:

$ cd
$ bzip2 -dc STLport-5.0.1.tar.bz2 | tar x
$ mv STLport stlport-5.0.1
$ cd stlport-5.0.1/build/lib
$ ./configure --no-cygwin
$ make -f gcc.mak install-release-static
  

Edit stlport-5.0.1/stlport/stl/_site_config.h to uncomment _STLP_NO_CYGWIN.

Boost-jam

Download the latest precompiled boost-jam binary for Windows from the Boost website (follow the "Download" link on the right). The package name will be something like boost-jam-3.1.12-1-ntx86.zip. Then follow these installation instructions:

$ cd
$ unzip boost-jam-3.1.12-1-ntx86.zip
$ cp boost-jam-3.1.12-1-ntx86/bjam.exe /usr/local/bin/
$ chmod ug+x /usr/local/bin/bjam
$ bjam -v
Boost.Jam  Version 3.1.12. OS=NT.
  

Boost

Download Boost libraries version 1.33.1 from the Boost website (follow the "Download" link on the right). Then follow these build instructions:

$ cd
$ bzip2 -dc boost_1_33_1.tar.bz2 | tar x

$ cd boost_1_33_1/libs/filesystem/build/
$ bjam -sTOOLS=mingw-stlport "-sBUILD=release <runtime-link>static" \
"-sGXX=g++ -mno-cygwin -D_REENTRANT" \
-sSTLPORT_5.0.1_PATH=../../../../stlport-5.0.1 -sSTLPORT_VERSION=5.0.1

$ cd ../../regex/build
$ bjam -sTOOLS=mingw-stlport "-sBUILD=release <runtime-link>static" \
"-sGXX=g++ -mno-cygwin -D_REENTRANT" \
-sSTLPORT_5.0.1_PATH=../../../../stlport-5.0.1 -sSTLPORT_VERSION=5.0.1

$ cd ../../../stage/lib/
$ ln -s libboost_filesystem-mgw-sp-1_33_1.lib libboost_filesystem-gcc-1_33_1.a
$ ln -s libboost_regex-mgw-sp-1_33_1.lib libboost_regex-gcc-1_33_1.a
  

Xerces-C++

Note that the libxsd-backend library (see below) prior to version 1.10.0 used to depend on some of the Xerces-C++ internal headers which are not available once Xerces-C++ is installed or packaged. Therefore you may need to use the source release of Xerces-C++.

Download the latest Xerces-C++ source release from the Xerces-C++ download page. Then follow these build instructions:

$ cd
$ gzip -dc xerces-c-src_2_8_0.tar.gz | tar x
$ export XERCESCROOT=~/xerces-c-src_2_8_0
$ cd xerces-c-src_2_8_0/src/xercesc
$ ./runConfigure -p mingw-msys -c gcc -x g++ -n fileonly \
-r none -s -z -mno-cygwin -C --host=i686-mingw32
$ make
  

Libcult

Download the latest libcult source release from the libcult website. Then follow these build instructions:

$ cd
$ bzip2 -dc libcult-1.2.0.tar.bz2 | tar x
$ cd libcult-1.2.0
$ make

Please select the C++ compiler you would like to use:
(1) GNU C++ (g++)
(2) Intel C++ (icc)
[1]: 1

Would you like the C++ compiler to optimize generated code?
[y]: n

Would you like the C++ compiler to generate debug information?
[y]: n

Please enter any extra C++ preprocessor options.
[]: -I ~/stlport-5.0.1/stlport -D_REENTRANT

Please enter any extra C++ compiler options.
[]: -mno-cygwin

Please enter any extra C++ linker options.
[]: -L ~/stlport-5.0.1/lib

Please enter any extra C++ libraries.
[]: -lstlport.5.0

Would you like to build a multi-threaded version of 'libcult'?
[y]: n

Would you like to build the network subsystem of 'libcult'?
[y]: n

Would you like to build the data representation subsystem of 'libcult'?
[y]: n

Please select the default library type:
(1) archive
(2) shared object
[2]: 1

Please enter the g++ binary you would like to use, for example 'g++-3.4',
'/usr/local/bin/g++' or 'distcc g++'.
[g++]: g++
  

Libfrontend-elements

Download the latest libfrontend-elements source release from the libfrontend-elements website. Then follow these build instructions:

$ cd
$ bzip2 -dc libfrontend-elements-1.0.2.tar.bz2 | tar x
$ cd libfrontend-elements-1.0.2
$ make

Please select the C++ compiler you would like to use:
(1) GNU C++ (g++)
(2) Intel C++ (icc)
[1]: 1

Would you like the C++ compiler to optimize generated code?
[y]: n

Would you like the C++ compiler to generate debug information?
[y]: n

Please enter any extra C++ preprocessor options.
[]: -I ~/stlport-5.0.1/stlport -D_REENTRANT

Please enter any extra C++ compiler options.
[]: -mno-cygwin

Please enter any extra C++ linker options.
[]: -L ~/stlport-5.0.1/lib

Please enter any extra C++ libraries.
[]: -lstlport.5.0

Please select the default library type:
(1) archive
(2) shared object
[2]: 1

Would you like to configure dependency on the installed
version of 'libcult' as opposed to the development build?
[y]: n

Please enter the src_root for 'libcult'.
[]: ../libcult-1.2.0

Please enter the out_root for 'libcult'.
[/home/boris/libcult-1.2.0]: ../libcult-1.2.0

Please enter the g++ binary you would like to use, for example 'g++-3.4',
'/usr/local/bin/g++' or 'distcc g++'.
[g++]: g++
  

Libbackend-elements

Download the latest libbackend-elements source release from the libbackend-elements website. Then follow these build instructions:

$ cd
$ bzip2 -dc libbackend-elements-1.0.4.tar.bz2 | tar x
$ cd libbackend-elements-1.0.4
$ make

Please select the C++ compiler you would like to use:
(1) GNU C++ (g++)
(2) Intel C++ (icc)
[1]: 1

Would you like the C++ compiler to optimize generated code?
[y]: n

Would you like the C++ compiler to generate debug information?
[y]: n

Please enter any extra C++ preprocessor options.
[]: -I ~/stlport-5.0.1/stlport -D_REENTRANT

Please enter any extra C++ compiler options.
[]: -mno-cygwin

Please enter any extra C++ linker options.
[]: -L ~/stlport-5.0.1/lib

Please enter any extra C++ libraries.
[]: -lstlport.5.0

Please select the default library type:
(1) archive
(2) shared object
[2]: 1

Would you like to configure dependency on the installed version
of 'boost libraries' as opposed to the development build?
[y]: n

Please enter the 'boost' root directory.
[]: ../boost_1_33_1

Please select the library type you would like to use:
(1) archive
(2) shared object
[2]: 1

Would you like to configure dependency on the installed
version of 'libcult' as opposed to the development build?
[y]: n

Please enter the src_root for 'libcult'.
[]: ../libcult-1.2.0

Please enter the out_root for 'libcult'.
[/home/boris/libcult-1.2.0]: ../libcult-1.2.0

Please enter the g++ binary you would like to use, for example 'g++-3.4',
'/usr/local/bin/g++' or 'distcc g++'.
[g++]: g++
  

Libxsd-frontend

Download the latest libxsd-frontend source release from the libxsd-frontend project page. Then follow these build instructions:

$ cd
$ bzip2 -dc libxsd-frontend-1.6.0.tar.bz2 | tar x
$ cd libxsd-frontend-1.6.0
$ make

Please select the C++ compiler you would like to use:
(1) GNU C++ (g++)
(2) Intel C++ (icc)
[1]: 1

Would you like the C++ compiler to optimize generated code?
[y]: n

Would you like the C++ compiler to generate debug information?
[y]: n

Please enter any extra C++ preprocessor options.
[]: -I ~/stlport-5.0.1/stlport -D_REENTRANT -DXML_LIBRARY

Please enter any extra C++ compiler options.
[]: -mno-cygwin

Please enter any extra C++ linker options.
[]: -L ~/stlport-5.0.1/lib

Please enter any extra C++ libraries.
[]: -lstlport.5.0

Please select the default library type:
(1) archive
(2) shared object
[2]: 1

Would you like to configure dependency on the installed version
of 'libfrontend-elements' as opposed to the development build?
[y]: n

Please enter the src_root for 'libfrontend-elements'.
[]: ../libfrontend-elements-1.0.2

Please enter the out_root for 'libfrontend-elements'.
[/home/boris/libfrontend-elements-1.0.2]: ../libfrontend-elements-1.0.2

Would you like to configure dependency on the installed
version of 'libcult' as opposed to the development build?
[y]: n

Please enter the src_root for 'libcult'.
[]: ../libcult-1.2.0

Please enter the out_root for 'libcult'.
[/home/boris/libcult-1.2.0]: ../libcult-1.2.0

Would you like to configure dependency on the installed version
of 'libxerces-c' as opposed to the development build?
[y]: n

Please enter the 'libxerces-c' root directory.
[]: ../xerces-c-src_2_8_0

Please select the library type you would like to use:
(1) archive
(2) shared object
[2]: 1

Would you like to configure dependency on the installed version
of 'boost libraries' as opposed to the development build?
[y]: n

Please enter the 'boost' root directory.
[]: ../boost_1_33_1

Please select the library type you would like to use:
(1) archive
(2) shared object
[2]: 1

Please enter the g++ binary you would like to use, for example 'g++-3.4',
'/usr/local/bin/g++' or 'distcc g++'.
[g++]: g++
  

XSD

Download the latest XSD source release from the XSD project page. Then follow these build instructions:

$ cd
$ bzip2 -dc xsd-2.1.0.tar.bz2 | tar x
$ cd xsd-2.1.0/xsd
$ make

Would you like to build optional parts of 'xsd' that require 'ACE'?
[n]: n

Please select the C++ compiler you would like to use:
(1) GNU C++ (g++)
(2) Intel C++ (icc)
[1]: 1

Would you like the C++ compiler to optimize generated code?
[y]: n

Would you like the C++ compiler to generate debug information?
[y]: n

Please enter any extra C++ preprocessor options.
[]: -I ~/stlport-5.0.1/stlport -D_REENTRANT -DXML_LIBRARY

Please enter any extra C++ compiler options.
[]: -mno-cygwin

Please enter any extra C++ linker options.
[]: -L ~/stlport-5.0.1/lib

Please enter any extra C++ libraries.
[]: -lstlport.5.0

Would you like to configure dependency on the installed
version of 'libxsd-frontend' as opposed to the development build?
[y]: n

Please enter the src_root for 'libxsd-frontend'.
[]: ../../libxsd-frontend-1.6.0

Please enter the out_root for 'libxsd-frontend'.
[/home/boris/libxsd-frontend-1.6.0]: ../../libxsd-frontend-1.6.0

Would you like to configure dependency on the installed version
of 'boost libraries' as opposed to the development build?
[y]: n

Please enter the 'boost' root directory.
[]: ../../boost_1_33_1

Please select the library type you would like to use:
(1) archive
(2) shared object
[2]: 1

Would you like to configure dependency on the installed version
of 'libbackend-elements' as opposed to the development build?
[y]: n

Please enter the src_root for 'libbackend-elements'.
[]: ../../libbackend-elements-1.0.4

Please enter the out_root for 'libbackend-elements'.
[/home/boris/libbackend-elements-1.0.4]: ../../libbackend-elements-1.0.4

Would you like to configure dependency on the installed
version of 'libcult' as opposed to the development build?
[y]: n

Please enter the src_root for 'libcult'.
[]: ../../libcult-1.2.0

Please enter the out_root for 'libcult'.
[/home/boris/libcult-1.2.0]: ../../libcult-1.2.0

Please enter the g++ binary you would like to use, for example 'g++-3.4',
'/usr/local/bin/g++' or 'distcc g++'.
[g++]: g++


$ ./xsd --version
XML Schema Definition Compiler 2.1.0
  

After this step the XSD compiler executable can be found in the xsd-2.1.0/xsd directory. Note that you've just built a native Win32 executable and as such it expects Win32 paths. As a result, you cannot use absolute Cygwin paths (e.g., /tmp/schema.xsd) with this binary.