[serialization] Difficulties with shared_ptr and export.hpp
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:
// A.cpp
#include "A.hpp"
...
// export.hpp header should be last;
#include
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_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
#include
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 &,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
Robert Ramey wrote:
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.
Reference -> Special Considerations -> Exporting Class Serialization (at the very end)
In fact, my implementation file contains *only* BOOST_CLASS_EXPORT statements.
Then no code will be instantiated - as you have indeed found.
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?
Code like this seems to compile only if I also include archive headers like: #include
#include 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 ]
Send me a little code that reproduces the problem.
I'll see if I can reproduce my error with a simple example. Thanks! Deane
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
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
#include 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
Robert Ramey wrote:
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
.... #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
Robert,
First, thank you very much for taking the time to answer my clueless
questions.
Second, I'm not sure what I get when I check out the boost files using
CVS, as instructed in the "Getting Started" section of the web site. Do
I have "HEAD" this way? If not, how do I get it?
Third, here is some code that reproduces my error. I'm sorry if it's a
bit overly complicated; I just don't know what exactly is causing the error.
#include
Deane Yang wrote:
Second, I'm not sure what I get when I check out the boost files using CVS, as instructed in the "Getting Started" section of the web site. Do I have "HEAD" this way? If not, how do I get it?
Its clear to me that you have the "HEAD". This error only appears in the HEAD branch of the cvs tree. You should make sure that HEAD is what you want. The head is where the development code is - RC_1_34 is where the next release versionis and the "normal" current one for users is Boost 1.33. By using the HEAD, you're helping debug the libraries and its much appreciated. But you should know that that is what you're doing. So I traced your error to and error in a recent enhancement that I've checked in to the HEAD branch. I'll check in a correction is a few days. Robert Ramey
Robert Ramey wrote:
Deane Yang wrote:
Second, I'm not sure what I get when I check out the boost files using CVS, as instructed in the "Getting Started" section of the web site. Do I have "HEAD" this way? If not, how do I get it?
Its clear to me that you have the "HEAD". This error only appears in the HEAD branch of the cvs tree. You should make sure that HEAD is what you want. The head is where the development code is - RC_1_34 is where the next release versionis and the "normal" current one for users is Boost 1.33. By using the HEAD, you're helping debug the libraries and its much appreciated. But you should know that that is what you're doing.
Thanks for the advice! I guess I'm living dangerously. I'll have to figure out how to check out the RC_1_34 code instead.
So I traced your error to and error in a recent enhancement that I've checked in to the HEAD branch. I'll check in a correction is a few days.
Ach. I was sure I was doing something dumb. Thanks very much for your help with this! Deane
Robert Ramey
participants (2)
-
Deane Yang
-
Robert Ramey