Boost logo

Boost Users :

Subject: [Boost-users] [Serialization] msvc derived class in dll throws archive_exception::unregistered_class
From: drivehappy (drivehappy_at_[hidden])
Date: 2012-07-06 15:14:34


Hi,

This is (yet another) question about the
archive_exception::unregistered_class ("derived class not registered
or exported"). I've tried to find as much information before posting
here, but frankly I'm stumped at this point. I believe this SO topic
(http://stackoverflow.com/questions/9189055/put-the-serialization-of-a-class-into-a-dll)
is pretty much the exact same problem I'm having if you want more code
to look at.

The problem is that the archive_exception::unregistered_class
exception is thrown when attempting to serialize via a base class
pointer that is instantiated as a derived type defined in a shared
library (DLL). The declaration and definition for the serialization is
split between a header/cpp respectively. Serializing in the same
manner, but with the derived class defined in the same executable
works correctly.

To hopefully answer the easy questions right away: the header contains
the BOOST_CLASS_EXPORT_KEY macro and the cpp contains the
BOOST_CLASS_EXPORT_IMPLEMENT with the defined exported templated
functions for the binary_iarchive and binary_oarchive, e.g.:

header:
BOOST_CLASS_EXPORT_KEY(derivedClass)

cpp:
BOOST_CLASS_EXPORT_IMPLEMENT(derivedClass)
template LIB_LINKAGE void
derivedClass::serialize(boost::archive::binary_iarchive & ar, const
unsigned int version);
template LIB_LINKAGE void
derivedClass::serialize(boost::archive::binary_oarchive & ar, const
unsigned int version);

The derivedClass::serialize contains the serialization for the base class, e.g.:
template <class Archive>
void ModuleStarted::serialize(Archive & ar, unsigned int) {
    ar & boost::serialization::base_object<baseClass>(*this);
}

My problem only exists under msvc (have not tried other versions but
using 9 with SP1), building under g++ 4.6.3 works correctly. I have
tested with Boost 1.49.0 and 1.50.0. Some discussions mentioned
placing the BOOST_CLASS_EXPORT_* macros after the export.hpp #include,
and even having the export.hpp included after the archive headers, all
of which don't appear to work.

I have also created a standalone VS solution with the executable and
dll projects from the Boost.Serialization test code (test_dll_export,
with polymorphic_base and polymorphic_derived2) and the same problem
still occurs. I have attached this file (unfortunately the include
paths will need to be modified) - it's built against Boost 1.50.0.

I've looked at the following discussions:
http://www.boost.org/doc/libs/1_50_0/libs/serialization/doc/special.html#dlls
(The manual, I've triple-checked this).
http://lists.boost.org/boost-users/2011/01/65295.php (Robert modified
a VS solution but the zip was never attached properly, so I cannot
check this).

Thanks,
Mark




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