[serialization] register_type and dll/so module

Hi, In the serialization library, when classes are never serialized directly but rather through a pointer to the base class, the user need to call register_type so that the archive contains information about the derived classes. However, sometimes those derived classes are implemented in another dynamic loaded (dll/so) module. The type of the derived classes will not be known at compile time. How can cope with this? Does the library provide any facilities to help the user in this situation? Best regards, Lirong

Li Lirong wrote:
Hi,
In the serialization library, when classes are never serialized directly but rather through a pointer to the base class, the user need to call register_type so that the archive contains information about the derived classes.
However, sometimes those derived classes are implemented in another dynamic loaded (dll/so) module. The type of the derived classes will not be known at compile time. How can cope with this? Does the library provide any facilities to help the user in this situation?
There's BOOST_CLASS_EXPORT. Take a look at http://www.rrsd.com/boost/libs/serialization/doc/traits.html#export In a previous version there were some problems with it, but at least for text_archives it worked. Robert might have fixed those problems though. - Volodya

Vladimir Prus wrote:
There's BOOST_CLASS_EXPORT. Take a look at http://www.rrsd.com/boost/libs/serialization/doc/traits.html#export
Thanks for the link. However, the current BOOST_CLASS_EXPORT mechanism will not work with DLLs. That's because global/static variable (the extended_type_info_typeid instance) is not shared by DLLs. I guess we may have to make the serialization library a dll and export the extended_type_info_typeid instance as a global variable. Regards, Lirong

Li Lirong wrote:
Vladimir Prus wrote:
There's BOOST_CLASS_EXPORT. Take a look at http://www.rrsd.com/boost/libs/serialization/doc/traits.html#export
Thanks for the link. However, the current BOOST_CLASS_EXPORT mechanism will not work with DLLs. That's because global/static variable (the extended_type_info_typeid instance) is not shared by DLLs.
I think this used to work for my project, which uses DLL.
I guess we may have to make the serialization library a dll and export the extended_type_info_typeid instance as a global variable.
Probably, the reason it worked for me is that I had shared library.. - Volodya
participants (2)
-
Li Lirong
-
Vladimir Prus