[xsd-users] MSVC - static variable initialisation

Martin Nickolas marty at tibra.com.au
Mon Oct 9 07:12:31 EDT 2006


Hi,

I am using XSD 2.3.0 with GCC 3.4.6 and MSVC 8 and I am experiencing 
some differences in behaviour between the two. I think the problem is 
really a difference between the two compilers but perhaps someone can 
shed some light on things...

I have a base schema (BS) with a type declared abstract, then another 
schema (DS) that declares a type based on that abstract type.

I use XSD to generate code for each schema. I am using the 
--generate-polymorphic flag.

The code for BS is compiled into a library (BL).
When the code for DS is compiled into an exe (E1) and statically linked 
to BL there is no problem.
But when the code for DS is compiled into a library (DL) and then 
another exe is created (E2) which links to both BL and DL with GCC, 
again, there is no problem but with MSVC the exe (E2) fails to parse 
valid xml files.

I have been stepping through the XSD source code and generated code 
while running E2 and have discovered the following:
- An exception of type no_type_info<> is thrown. It simple contains the 
message:
    no type information available for type ''
- This exception is thrown from type_factory_map<>::find_type() as that 
function tries to find the factory for the derived type in DS.
- It appears that XSD generated code generates a static variable of type 
::xsd::cxx::tree::type_factory_initializer<>  for declared types whose 
constructor has the job of inserting a factory for that type into 
type_factory_map::type_map_. So factories for all types should be 
installed even before main is called.
- It seems that with MSVC the constructor of this static variable is 
never called when that var is declared in an object file build into a 
lib (but it is called when built into an exe).

The result of this is that E2 fails to parse a valid xml file even 
though E1 does.

Has anyone seen this problem before? Is it really conceivable that 
static variables aren't getting initialised in a lib? Is there a better 
work-around than just doing away with the libs and building all the code 
straight into the final exe?

Thanks,

CYA




More information about the xsd-users mailing list