Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-11-23 02:20:51


Deane Yang wrote:
> First, I am trying to figure out how to use BOOST_CLASS_EXPORT. I am
> trying to do it using the following advice from the documentation:
>
> "As noted in the comments, this would work. But #include
> <.../export.hpp> can't be used without conflicting with other modules
> which use #include <.../*archive.hpp>. In this case we can move the
> export to an implementation file:

Where did you find this in the documentation? I know its in there but
I can't find it when I look for it in the HEAD.

>
> // A.cpp
> #include "A.hpp"
> ...
> // export.hpp header should be last;
> #include <boost/serialization/export.hpp>
> ...
> BOOST_CLASS_EXPORT(A)
> ..."
>
> 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.

> Is this correct? (I didn't see anything about this in the
> documentation)

In the section:
Exporting Class Serialization
... "we have described BOOST_CLASS_EXPORT. This is used to make the
serialization library aware that code should be instantiated for
serialization of a given class even though the class hasn't been otherwise
referred to by the program. This functionality is necessary to implement
serialization of pointers through a virtual base class pointer. That is, a
polymorphic pointer."

maybe that explanation should be made more complete. The usage of
BOOST_CLASS_EXPORT
will ensure that appropriate code to serialize the indicated type is
generated for all archive types (and only those archive types) included when
BOOST_CLASS_EXPORT is used.

> But now if a class that is being exported contains a
> boost::shared_ptr<..> member (so I have to #include
> boost/serialization/shared_ptr.hpp), then I get the following
> compilation errors (in MSVC8.0express):

> ..\..\..\vendor\boost\boost/serialization/shared_ptr.hpp(134) : error
> C2039: 'reset' : is not a member of
> 'boost::archive::naked_xml_iarchive'
> ..\..\..\vendor\boost\boost/archive/xml_iarchive.hpp(91) : see
> declaration of 'boost::archive::naked_xml_iarchive'
> ..\..\..\vendor\boost\boost/serialization/split_free.hpp(58) :
> see reference to function template instantiation 'void
> boost::serialization::load<Archive,AndrewKalotayAssociates::Basic::Output::ValuationReport>(Archive
> &,boost::shared_ptr<T> &,const unsigned int)' being compiled
>
> Can someone tell from this what I'm doing wrong?

Send me a little code that reproduces the problem.

Robert Ramey


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