[xsd-users] Problems linking Code which uses XSD in Release mode

Boris Kolpackov boris at codesynthesis.com
Wed Nov 12 10:23:54 EST 2008


Hi Jan,

[I've CC'ed xsd-users in case someone else encounters a similar problem.]


Jan Klimke <jan.klimke at hpi.uni-potsdam.de> writes:

> i managed to create a solution which does not run ;-).

Thanks for the test case. I did some digging and here is what I
uncovered.

When you inherit an exported class from a base that is a class
template, VC++ automatically instantiates and export this class
template. Similarly, when the class is imported, the base template
is not instantiated but is rather imported. For example:

template <typename X>
struct Foo
{
  void f ();
};

struct WFS_API Bar: Foo<int>
{
};

Here, when WFS_API expands to __declspec(dllexport), Foo<int>::f() 
is automatically instantiated and also exported. When WFS_API is
__declspec(dllimport) and Foo<int>::f() is used, it is not 
instantiated but instead the symbol from the DLL is used.

This normally works fairly well which is the reason we haven't heard 
of any such problems before. But in your case something happens to 
VC++ and it doesn't instantiate the two symbols that end up unresolved.
I think what happens is that in the DLL the compiler optimizes those
functions away (since they are inline) but, for some reason, does not 
do the same in the executable even though both are compiled with the
same options.

It seems the only solution is to request explicit instantiation and 
exporting/importing as you have shown in one of your previous emails:

template class WFS_API ::xsd::cxx::tree::ncname< char, Name >;

We are thinking of adding an option that would instruct the compiler
to generate these requests automatically for all built-in types. Let 
me know if you would like a pre-release binary with this support.


> By the way, do you have an explanation for the compile warnings
> concerning the custom-type templates ?

Yes, this is actually related to the mechanism described above.
Other generated types derive from your custom types and VC++
tries to instantiate and export them. But the definitions for
their functions are hidden in the .cpp file where you instantiate
the template explicitly. So the warnings are bogus and can be
safely ignored. We will suppress them in the next release of XSD.
You can also do it by adding the following line:

#pragma warning (disable:4661)

After #pragma warning (disable:4250) in libxsd/xsd/cxx/compilers/vc-8/pre.hxx.

Boris




More information about the xsd-users mailing list