[Serialization] Problem serializing directly and through base pointer in the same program.
Hi,
I am using Boost.Serialization to serialize classes through a shared_ptr to
an abstract base class. Sometimes, I also serialize these classes directly. This
was working for me in version 1.40, but not versions 1.41 or 1.44.
If I serialize only shared_ptr<BaseClass> instances, everything is fine.
If I link in code that serializes the derived class directly, even if that code
is never called, serialization of shared_ptr<BaseClass> instances throws an
exception ("unregistered class").
A few notes about what I am doing:
I am calling BOOST_CLASS_EXPORT in the implementation file for each serializable
class.
I am using a template function for serialization that accepts any serializable
type, creates a new text_oarchiver on the stack, and returns a string. This is
called from many places in my application with many different types of things
(making it hard to have a central place to put all the BOOST_CLASS_EXPORTs).
I am having this problem on RHEL5 with gcc 4.1.2 WITHOUT optimization turned
on. It works as expected with -O1 or higher. On WinXP with Visual Studio 2005,
it fails in both release and debug mode.
The problem also seems to depend on the order that the object files get
written into the executable. If I include the file that is calling
BOOST_CLASS_EXPORT first, things work as expected, but fail otherwise.
(e.g., g++ obj.cpp main.cpp ... works, g++ main.cpp obj.cpp ... fails).
Here are 3 source files, obj.h, obj.cpp, main.cpp that demonstrate this
problem. The line in main:
fromString(toString(obj), obj2);
causes the code just before it (using shared_ptr) to fail. If anyone
can let me know
if I am misusing the library somehow, or if there is a cleaner way to accomplish
what I am trying to do, I would be very appreciative.
Thanks,
Travis Abbott
--------------------------8< obj.h 8< --------------------------
#pragma once
#include
Travis Abbott wrote:
if I am misusing the library somehow, or if there is a cleaner way to accomplish what I am trying to do, I would be very appreciative.
One thing I would look into would be to "upgrade" the BOOST_EXPORT_CLASS macros to the new macros ...EXPORT_KEY and ... EXPORT_IMPL as described in the documentation. This addresses some ambiguous situations regarding registration of exportable types. Robert Ramey
On Mon, Sep 20, 2010 at 8:35 PM, Robert Ramey
Travis Abbott wrote:
if I am misusing the library somehow, or if there is a cleaner way to accomplish what I am trying to do, I would be very appreciative.
One thing I would look into would be to "upgrade" the BOOST_EXPORT_CLASS macros to the new macros ...EXPORT_KEY and ... EXPORT_IMPL as described in the documentation. This addresses some ambiguous situations regarding registration of exportable types.
Robert Ramey
...EXPORT_KEY and ...EXPORT_IMPL did the trick. I missed those in the docs. Thank you for your quick help. Travis Abbott
participants (2)
-
Robert Ramey
-
Travis Abbott