[xsd-users] Issue with using xsd generated code in DLLs with
Visual Studio 2010
Boris Kolpackov
boris at codesynthesis.com
Fri Sep 17 09:40:49 EDT 2010
Hi Timo,
Timo Geusch <timo.geusch at styleadvisor.com> writes:
> It looks like Microsoft did change the implementation of their standard
> library in VS2010 however, and as a side effect it appears that classes
> which derive from standard C++ classes like std::basic_string etc trigger
> an export of their base class's symbols. In other words, the class
> xsd::cxx::string as defined in cxx/tree/types.hxx results in the DLL
> exporting most of std::basic_string. Try to link two DLLs that both
> use and export a generated schema and the build will fail with the
> linker complaining about duplicate symbols.
I think this can be resolved by exporting the types in the XML Schema
namespace. Here is how this can be done:
1. Generate the XML Schema namespace headers with the --export-xml-schema
and --export-symbol options, for example:
xsd cxx-tree --generate-xml-schema --export-xml-schema \
--export-symbol XML_SCHEMA_EXPORT xml-schema.xsd
2. Place the generated file into a "root" DLL of your DLL hierarchy.
By root I mean that this DLL will be used by all other DLLs that
use XSD generated code.
If no other C++ source file uses the xml-schema.hxx header in
this DLL, then create a dummy file, say xml-schema.cxx, include
xml-schema.hxx into it, and add it to the project (this will
make sure the types are actually instantiated and exported).
The XML_SCHEMA_EXPORT macro should expand to __declspec(dllexport)
when building this DLL and to __declspec(dllimport) otherwise.
Normally you would create the standard "export" header and include
it into xml-schema.hxx with --hxx-prologue option.
3. Compile all your other schemas with the --extern-xml-schema xml-schema.xsd
option so that they all use the header generated on step 1.
Let me know if this works for you.
Boris
More information about the xsd-users
mailing list