|
Boost Users : |
From: John Pye (john.pye_at_[hidden])
Date: 2007-09-03 04:55:43
((( All -- please ignore my previous post; I have resolved the problem
and didn't intend to send that message )))
Hi Jeshua,
Vaguely related comment on your problem. I was also recently seeing this
"unregistered void cast" runtime error. As far as I could tell it was a
problem relating to my ordering and placement of "#include
<boost/archive/text_oarchive.hpp> (or ditto iarchive), and "#include
<boost/serialization/export.hpp> as well as calls to BOOST_CLASS_EXPORT.
It was nothing to do with my use of void_cast_register, which in fact I
don't use anywhere in any of my code.
So FWIW I think that this error message is not particularly helpful or
well-worded.
Cheers
JP
Jeshua Bratman wrote:
> I already sent a message on this topic a few weeks ago, however, my problem
> has a changed a bit so I decided to post a new message.
>
> I've been trying to get Boost serialization working for dynamically loaded
> shared libraries. Here's my basic structure simplified:
>
> 1. base.hpp - includes an abstract base class called base
> 2. derived.hpp - includes a derived class from base. includes base.hpp.
> 3. derived.cpp - includes code for derived class and for dynamically loading
> it
> 4. main.cpp - includes base.hpp but NOT derived.hpp. dynamically loads
> instantiates a base * which points to a derived object from derived.so
>
> Now in main I want to be able to serialize my pointer to the loaded derived
> class:
>
>
> base *obj = create_func(); //obj now points to a derived object
> obj->test(); //when test is run it correctly outputs the message from
> derived.cpp
>
> const base* const to_serialize = obj;
> std::ofstream ofs("filename");
> boost::archive::text_oarchive oa(ofs);
> try
> {
> oa << (to_serialize);
> }
> catch(exception &e)
> {
> cout << "Exception: " << e.what() << "\n";
> }
>
> It compiles fine and I got past the "unregisterd class" problem, but now
> when I try to serialize the pointer an exception is caught:
> "Unregistered void cast"
>
> This appears to be a problem with registering the derived pointer type from
> the base type when dynamically loaded from a shared library.
>
> However, I do register the derived-base relationship as suggested in the
> documentation. The serialize method in derived.hpp is as follows:
>
> template<class Archive>
> void serialize(Archive & ar, const unsigned int version)
> {
>
> ar.template register_type(static_cast<derived *>(NULL));
> //ar & boost::serialization::base_object<base>(*this);
> ar & data;
> boost::serialization::void_cast_register(
> static_cast<derived *>(NULL),
> static_cast<base *>(NULL)
> );
> }
>
> If anyone knows the cause of this and/or a solution I would be very
> appreciative. I've been working at this for a long time now and I'm almost
> ready to write my own simple serialization for my specific purpose.
>
> Thank you for your help,
> Jeshua Bratman
>
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