
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Robert Ramey Sent: 19 December 2010 22:48 To: boost-users@lists.boost.org Subject: Re: [Boost-users] serialization: "derived class not registered orexported" exception , 1.45 boost
Hicham Mouline wrote:
Hello,
I have moved all serialization code in a separate static library that I called serialization. This, in my case, depends on mpi. The headers in this static library: 1. include
2. include the definition of the derived class being serialized 3. declare a template function serialize() that takes a reference to the derived class being serialized in the boost::serialization namespace 4. invoke the BOOST_CLASS_EXPORT_KEY(<derivedclass>) macro at the global namespace scope The corresponding source files in this static library: 1. include the header 2. define the function template serialize() 3. explicitly instantiate the serialize() function with all the archives used: mpi::packed_iarchive and mpi::packed_oarchive in the boost::serialization namespace 4. invoke the BOOST_CLASS_EXPORT_IMPLEMENT(<derivedclass>) macro at the global namespace scope
The main program links against this static library, and invokes a mpi function (broadcast) that serializes by the base pointer. The base class is polymorphic. All class derivations are public.
Debugging, the code reaches : archive/detail/oserializer.hpp
boost::archive::detail::save_pointer_typeboost::mpi::packed_oarchive: :polymorphic::save<baseclass>(boost::mpi::packed_oarchive
& ar={...}, baseclass& t={...}) Line 400 + 0x38 bytes
where NULL==true_type
However, looking at the t argument of save(), it shows that is the correct derived object. But the type T is the base class.
What am I missing?
Not much, you're almost there.
You've invoked the EXPORT macros so the runtime static objects are created in the library. So far, so good. But you're mainline doesn't refer to them, so they are not included in your executable. I think the easiest way to do this is to include in the execution build something like:
my_module.cpp
#include "my_type.hpp" BOOST_SERIALIZATION_EXPORT_IMPL(my_type) ... other types.
I've just tried this. Do you mean BOOST_CLASS_EXPORT_IMPLEMENT? I can't find BOOST_SERIALIZATION_EXPORT_IMPL anywhere in boost/serialization nor archive headers. when I tried BOOST_CLASS_EXPORT_IMPLEMENT, it complained about a member g begin defined twice, in my serialization lib, and my main code, rds,