Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-11-23 12:04:19


The real question here is:

> What else is supposed to be in this file? Do I need to put in the code
> that loads and saves archives in this file?

And here is the answer.

I expect that BOOST_CLASS_EXPORT will be specified in the same
header file as the class declaration to which it corresponds. That is,
BOOST_CLASS_EXPORT(T) is a "trait" of the class. This trait
is the "external name" used to identify the class and is needed when
serializing polymorphic types through a base class pointer.

I expect that one's program will generally look like:

#include <boost/archive/xml_oarchive.hpp>
....
#include "my_class.hpp" // which has BOOST_CLASS_EXPORT inside

In boost 1.35 (aka HEAD) these headers can be in any order. In 1.34
and earlier, the archive headers have to go before any headers which
contain BOOST_CLASS_EXPORT

This will instantiate any code required to serialize types specified
by BOOST_CLASS_EXPORT for each archive included. (note that
the code is instantiated regardless of whether or not it is actually
invoked.)

If no archive headers are included - no code should be instantiated. This
will permit BOOST_CLASS_EXPORT to be a permanent part of the
my_class declaration. (Right now this provokes an error message. I'll
rectify that.)

I hope this clarifies things.

Robert Ramey

Deane Yang wrote:
> Robert Ramey wrote:
>
>>>
>>> In fact, my implementation file contains *only* BOOST_CLASS_EXPORT
>>> statements.
>>
>> Then no code will be instantiated - as you have indeed found.
>

>>> Code like this seems to compile only if I also include archive
>>> headers like: #include <boost/archive/xml_oarchive.hpp>
>>> #include <boost/archive/xml_iarchive.hpp>
>>
>> correct.
>>
>>> If these directives are omitted, then my code does not compile.
>>
>> Hmmm - the required code to export class x to archive
>> xml_?archive.hpp will not be instantiated. I would expect that to
>> show up as a missing symbol during linking.
>
> No, I get something like:
>
> ..\..\..\..\vendor\boost\boost/serialization/type_info_implementation.hpp(48)
>> error C2027: use of undefined type
> 'boost::serialization::extended_type_info_impl<T>'
> with
> [
> T=Input::Bond
> ]
> ..\..\..\..\vendor\boost\boost/serialization/export.hpp(75) :
> see reference to class template instantiation
> 'boost::serialization::type_info_implementation<T>' being compiled
> with
> [
> T=Input::Bond
> ]
>

OK - I believe that is misleading. I'm changing my local copy to
#include <boost/serialization/extended_type_info.hpp> so that
this error doesn't appear.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net