Search code examples
windowsserializationdllcereal

VS2013 create several dll files with different classes to serialize with cereal


I tried to split some polymorphic classes to be serialized into a dll file. Then I get an exception for unregistered polymorphic type. The problem seems to be that the code create two instances of the map used to lookup polymorphic objects (Kept by template class cereal::detail::StaticObject). If I put the CEREAL_REGISTER_TYPE into the project that do the serialization, then everything works nice.
So I wonder if anyone know if it is possible to do some tricks to be able to do the registration in the dll file?
Is it possible to force the program to use the same instance of the cereal::detail::StaticObject class?


Solution

  • As of cereal v1.1.0 this problem can be solved by moving the polymorphic type registration to a header file, which will ensure that any translation unit including that header properly initializes its StaticObject. Just remember to include the archives you wish to bind to prior to calling the registration macro.

    There's more information available on the [main cereal documentation] site(http://uscilab.github.io/cereal/polymorphism.html), which has also been updated for 1.1.