[xsd-users] Building xsd with the eclipse cdt
Boris Kolpackov
boris at codesynthesis.com
Thu Jan 21 07:43:13 EST 2010
Hi Monika,
Huether, Monika <monika.huether at fkie.fraunhofer.de> writes:
> I'm working with eclipse 3.5 under linux and gcc and xercesc 3.0. I'm
> trying to run the xsd examples. In the xsde mailing list I found an
> example for building xsde with eclipse. What are the main differences
> between the xsd and xsde settings?
I have adapted these instructions for the XSD and the C++/Tree
mapping. So here are the step-by-step instruction for setting the
example/cxx/tree/hello/ example with Eclipse CDT. You can use the
same approach for other examples or your application. Here I assume
XSD is installed in /opt/xsd and that the Xerces-C++ library was
built and installed in /opt/xerces-c. If you haven't built Xerces-C++
yet you can try the following:
$ ./configure --prefix /opt/xerces-c
$ make
$ sudo make install
1. Create a directory for the hello example and copy driver.cxx,
hello.xml, and hello.xsd into it. Do not copy the makefile.
2. In Eclipse, do File->New->C++ Project. Type the directory
name from step 1 as project name so that the Location field
points to the directory created in step 1. Click Next then
Finish. At this stage Eclipse will try to build driver.cxx
which will result in compile errors. This is expected since
we haven't generated the C++ files from the schema yet.
3. In Project Explorer right-click on hello.xsd and select
Properties. Select C/C++ Build->Settings, select Build Steps
tab, and change Configuration to All. Change "Disable Custom
Build Step" to "Apply Custom Build Step Overriding Other Tools".
Leave Additional Input Files field blank. In output file names,
list all the generated C++ files with the '../' path, separated
by semicolon. In our case it will be:
../hello.hxx;../hello.cxx;../hello.ixx
In the Command field put the XSD compiler command line that is
used to compile the schema. Also add '--output-dir ..' and use the
'../' path for the schema file. In our case it will be:
/top/xsd/bin/xsd cxx-tree --generate-inline --output-dir .. ../hello.xsd
In the Description field put something like "xsd hello.xsd" or
"compiling hello.xsd". Click Ok to close the dialog.
4. In Project Explorer right-click on the project name and select
Properties. Select C/C++ General->Paths and Symbols, select
GNU C++, select Includes tab, and change Configuration to All.
Add the path for the libxsd library headers, /opt/xsd/libxsd
in our case. Then add the path for the Xerces-C++ headers,
/opt/xerces-c/include in our case. Change to the Library Paths
tab and add the path to the libxerces-c.so/libxerces-c.a libraries,
/opt/xerces-c/lib in our case. Click Apply.
Change to C/C++ Build->Settings->GCC C++ Linker->Libraries.
Add 'xerces-c' to the Libraries list. Click Ok to close the dialog.
5. Now Eclipse knows how to build the generated C++ files from the
schema. Unfortunately, Eclipse is not smart enough to figure out
that some files included in driver.cxx are those generated C++
files and it could have successfully compiled driver.cxx if only
it compiled the schema first.
So when we don't have the generated C++ files, we need to
"bootstrap" the project by explicitly compiling them. Once the
files are generated, Eclipse will figure out all the dependencies
and everything will work as expected (that is, if we modify
hello.xsd, Eclipse will know to first recompile hello.xsd and
only then recompile driver.cxx).
The easiest way to do this bootstrapping is to add a special
target that will trigger the schema compilation. Go to Project->
Make Targets->Create. In Target Name type something like Bootstrap.
Then uncheck the "Same as the target name" box and enter the name
of the generated file with the '../' path, one file per schema
is sufficient. In our case it will be ../hello.hxx. Click Ok
to close the dialog.
6. Now we can bootstrap the project by doing Project->Make Targets->
Build and selecting the Bootstrap target.
After that we can continue with normal builds.
Let me know if you run into any issue with this.
> I also can't find the xsd library file in the libxsd folder. Do I
> have to generate it?
No, libxsd is a header-only library so you don't need to build
anything for it.
Boris
More information about the xsd-users
mailing list