Using XSD with Qt Creator

From Code Synthesis Wiki

Jump to: navigation, search

Qt Creator for Windows

Qt Creator for Windows uses the MinGW port of GCC as the C++ compiler. MinGW toolchain is installed with the Qt Creator. The first step in using XSD with Qt Creator is to build the Xerces-C++ library with the same C++ compiler as used by Qt Creator. To do this follow these steps:

1. Install a basic Cygwin environment. You only need basic tools such as bash, sed, awk, and make. In particular, you don't need to install gcc since we will be using the one provided with Qt Creator. Instead of Cygwin you can try to use MSYS though it seems that Cygwin is much easier to install.

2. Start the Cygwin shell and set the PATH variable to include the MinGW bin directory that comes with Qt Creator:

$ export PATH=/cygdrive/c/Qt/QtCreator-x.y.z/mingw/bin:$PATH

3. Unpack the latest release of Xerces-C++ and configure and build it like this (we disable building the shared library since Qt Creator's MinGW only includes static libraries):

$ ./configure --host=i686-mingw32msvc --enable-transcoder-windows --enable-netaccessor-winsock --disable-shared CXXFLAGS=-O2 CFLAGS=-O2
$ cd src
$ make

4. Once the build completes, the headers are in src/ and the library is in src/.libs/. You can also install the library and the headers by using the --prefix configure option and the make install target.

5. To test that everything works as expected, you can try to build the XSD examples without using Qt Creator. To do this unpack the XSD Windows distribution and do:

$ cd xsd-x.y.x-windows-i686/examples
$ make CPPFLAGS=-Ic:/path/to/xerces-c-x.y.z/src LDFLAGS=-Lc:/path/to/xerces-c-x.y.z/src/.libs

After you have built the Xerces-C++ library you can build code generated by XSD from Qt Creator. For this to work, you will need to add the following include search paths to your project:

C:\path\to\xerces-c-x.y.z\src
C:\path\to\xsd-x.y.x-windows-i686\libxsd

So that the INCLUDEPATH variable in the .pro file reads as follows:

INCLUDEPATH += "C:\path\to\xerces-c-x.y.z\src \
               "C:\path\to\xsd-x.y.x-windows-i686\libxsd"

If you have installed XSD as an .msi package then the paths would be along these lines:

INCLUDEPATH += "C:\path\to\xerces-c-x.y.z\src" \
               "C:\Program Files\CodeSynthesis XSD X.Y\include"

Note also that it is important for the Xerces-C++ include path to come first in the latter case.

You will also need to add the following library search path as well as link to the Xerces-C++ library:

C:\path\to\xerces-c-x.y.z\src\.libs

So that the LIBS variable in the .pro file reads as follows:

LIBS += -L"C:\path\to\xerces-c-x.y.z\src\.libs" \
        -lxerces-c
Personal tools