[xsd-users] Issue with using xsd generated code in DLLs with Visual Studio 2010

Timo Geusch timo.geusch at styleadvisor.com
Wed Sep 22 21:12:57 EDT 2010


> > -----Original Message-----
> > From: Boris Kolpackov [mailto:boris at codesynthesis.com]
> > Sent: Tuesday, September 21, 2010 7:07 AM
> > To: Timo Geusch
> > Cc: xsd-users at codesynthesis.com; Thomas Witt
> > Subject: Re: [xsd-users] Issue with using xsd generated code in DLLs
> > with Visual Studio 2010
> >
> > Hi Timo,
> >
> > Timo Geusch <timo.geusch at styleadvisor.com> writes:
> >
> > > I've just tried this with a subset of the DLLs in the project.
> > > Unfortunately the suggested workaround still results in the same
> > > problem - the "root" DLL still exports symbols that are part of
> > > the std namespace - say, std::basic_string<char>::front() that
> > > subsequently clashes with the same symbol in one of the 'leaf'
> > > DLLs
> >
> > Are the clashing symbols in the leaf DLL also exported?
> 
> It doesn't get that far - the link stage of the build aborts before it
> completes due to the duplicate symbols that are both exported by the
> root DLL and present in the leaf DLL's object files.
> 
> I have a very minimal test project here that consists of two DLLs, a
> root DLL and a leaf DLL. The leaf DLL needs to link with the import
> library of the root DLL; If the root DLL contains an exported class
> that derives from std::string _and_ the leaf DLL makes use of
> std::string, the link stage for the leaf DLL will fail due to the root
> DLL exporting the symbols for std::string which have also been
> instantiated in the leaf DLL's object files. So this is not a problem
> specific to libxsd but rather a general issue.

After some more experimentation, it seems that the change in the std::string implementation in VS2010 exposed behaviour that is also present in the VS2008 toolchain. If the following conditions are met, the linker will complain of duplicate symbols and not be able to link the leaf DLL:

1) You derive an exported class from a non-exported header-only base class in the root DLL
2) You do the same in the leaf DLL
3) You also make use of the base class in the leaf DLL so the compiler actually has a reason to create an instance of the base class in the leaf DLL

The reason that this doesn't appear to be an issue in VS2008 when deriving from std::string is that in VS2008, std::string is not header-only.

With best regards,
Timo



More information about the xsd-users mailing list