boost serialization & module boundaries

Hi,
I'm trying to use boost to serialize a machine learning library that I'm
working with. It all worked out very conveniently, but it seems now,
that I have hit a dead end. I've been looking on the net but couldn't
find any information that worked for me, so here we go:
The problem is, that the library consists of several modules, which are
dynamically linked. For instance the class KernelMachine has a field
kernel of type Kernel, which is contained in a separate module (in the
sense of a shared object).
The following code compiles, but when I try to serialize a
CKernelMachine object I get an "unregistered_class" error. (CKernel does
serialize fine, when called directly)
class CKernelMachine : public CClassifier
{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & boost::serialization::base_object<CClassifier>(*this);
ar.register_type(static_cast

This is possible and I have tested such a facility. I haven't had time to move the latest version into the trunk but one can find at www.rrsd.com However, in order to do this, you will have to know how to use EXPORT correctly which does require a close reading of the manual. Sorry about that. RObert Ramey Christian Widmer wrote:
Hi,
I'm trying to use boost to serialize a machine learning library that I'm working with. It all worked out very conveniently, but it seems now, that I have hit a dead end. I've been looking on the net but couldn't find any information that worked for me, so here we go:
The problem is, that the library consists of several modules, which are dynamically linked. For instance the class KernelMachine has a field kernel of type Kernel, which is contained in a separate module (in the sense of a shared object).
The following code compiles, but when I try to serialize a CKernelMachine object I get an "unregistered_class" error. (CKernel does serialize fine, when called directly)
class CKernelMachine : public CClassifier {
private:
friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & boost::serialization::base_object<CClassifier>(*this);
ar.register_type(static_cast
(NULL)); ar & kernel; std::cout << "done CKernelMachine" << std::endl; }
protected: CKernel* kernel; };
I found some threads that pointed me towards BOOST_CLASS_EXPORT, but I'm not exactly sure how to use it.
So my question is - is it in principle even possible to serialize across module (shared-object) boundaries.
If so, how should I go about? Any pointers would be greatly appreciated.
- Chris

Dear Robert, thank you for your reply. After struggling with some other issues for a couple days, I've compiled boost-1.34 with the serialization patch from your website, as you suggested. In deed, the "unregistered class" problem disappeared, but was unfortunately replaced by a "unregistered void cast" exception when trying to serialize across shared-object boundaries. All classes are registered using BOOST_CLASS_EXPORT in their respective .cpp file, yet I can't get it to work. I attached a piece of my code to this email. The attached archive contains the following files: - Classifier.h - Classifier.cpp - Labels.h - Labels.cpp The class CClassifier has a field labels of type CLabels. The classes are contained in two separate shared-objects. When trying to serialize an object of type CClassifier, an exception gets thrown when attempting to serialize the field labels. Any ideas? Best regards, Christian Widmer Robert Ramey wrote:
This is possible and I have tested such a facility. I haven't had time to move the latest version into the trunk but one can find at www.rrsd.com However, in order to do this, you will have to know how to use EXPORT correctly which does require a close reading of the manual. Sorry about that.
RObert Ramey
Christian Widmer wrote:
Hi,
I'm trying to use boost to serialize a machine learning library that I'm working with. It all worked out very conveniently, but it seems now, that I have hit a dead end. I've been looking on the net but couldn't find any information that worked for me, so here we go:
The problem is, that the library consists of several modules, which are dynamically linked. For instance the class KernelMachine has a field kernel of type Kernel, which is contained in a separate module (in the sense of a shared object).
The following code compiles, but when I try to serialize a CKernelMachine object I get an "unregistered_class" error. (CKernel does serialize fine, when called directly)
class CKernelMachine : public CClassifier {
private:
friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & boost::serialization::base_object<CClassifier>(*this);
ar.register_type(static_cast
(NULL)); ar & kernel; std::cout << "done CKernelMachine" << std::endl; }
protected: CKernel* kernel; };
I found some threads that pointed me towards BOOST_CLASS_EXPORT, but I'm not exactly sure how to use it.
So my question is - is it in principle even possible to serialize across module (shared-object) boundaries.
If so, how should I go about? Any pointers would be greatly appreciated.
- Chris
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

I'm not sure what "shared object" means here. CClasifier contains: ... CLabels * labels; template<class Archive> serialize(Archive &ar , unsigned int version){ ar & labels; } .... Which should be fine as is if labels in fact a pointer to one instance of CLabels. If labels is a base class pointer to a more derived type, it,s THAT derived type which must be exported. Robert Ramey Christian Widmer wrote:
Dear Robert,
thank you for your reply. After struggling with some other issues for a couple days, I've compiled boost-1.34 with the serialization patch from your website, as you suggested.
In deed, the "unregistered class" problem disappeared, but was unfortunately replaced by a "unregistered void cast" exception when trying to serialize across shared-object boundaries.
All classes are registered using BOOST_CLASS_EXPORT in their respective .cpp file, yet I can't get it to work. I attached a piece of my code to this email. The attached archive contains the following files:
- Classifier.h - Classifier.cpp - Labels.h - Labels.cpp
The class CClassifier has a field labels of type CLabels. The classes are contained in two separate shared-objects. When trying to serialize an object of type CClassifier, an exception gets thrown when attempting to serialize the field labels. Any ideas?
Best regards,
Christian Widmer

Dear Robert, Robert Ramey wrote:
I'm not sure what "shared object" means here.
Shared-object in the sense of a dynamically linked library (DLL).
Which should be fine as is if labels in fact a pointer to one instance of CLabels.
If labels is a base class pointer to a more derived type, it,s THAT derived type which must be exported.
"labels" is in fact a pointer to a instance of CLabels, not a base class pointer. The code above works just fine if contained in the same shared-library (DLL). Not sure how to proceed. Best regards, Christian Widmer
Christian Widmer wrote:
Dear Robert,
thank you for your reply. After struggling with some other issues for a couple days, I've compiled boost-1.34 with the serialization patch from your website, as you suggested.
In deed, the "unregistered class" problem disappeared, but was unfortunately replaced by a "unregistered void cast" exception when trying to serialize across shared-object boundaries.
All classes are registered using BOOST_CLASS_EXPORT in their respective .cpp file, yet I can't get it to work. I attached a piece of my code to this email. The attached archive contains the following files:
- Classifier.h - Classifier.cpp - Labels.h - Labels.cpp
The class CClassifier has a field labels of type CLabels. The classes are contained in two separate shared-objects. When trying to serialize an object of type CClassifier, an exception gets thrown when attempting to serialize the field labels. Any ideas?
Best regards,
Christian Widmer
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

The code above works just fine if contained in the same shared-library (DLL). Not sure how to proceed.
What toolset are you using to build? There are some explicit warnings in the implementation notes like "Visual C++ 7.1 Derivation from an archive class defined in a DLL as described in ... will not work" HTH Jerry

So the issue is not related to "export". It is likely a question of template code instantiation. This subject is touched up by the example "demo_pimpl" and its related documentation. Check that out and see if it helps. Robert Ramey Christian Widmer wrote:
Dear Robert,
Robert Ramey wrote:
I'm not sure what "shared object" means here.
Shared-object in the sense of a dynamically linked library (DLL).
Which should be fine as is if labels in fact a pointer to one instance of CLabels.
If labels is a base class pointer to a more derived type, it,s THAT derived type which must be exported.
"labels" is in fact a pointer to a instance of CLabels, not a base class pointer. The code above works just fine if contained in the same shared-library (DLL). Not sure how to proceed.
Best regards,
Christian Widmer
Christian Widmer wrote:
Dear Robert,
thank you for your reply. After struggling with some other issues for a couple days, I've compiled boost-1.34 with the serialization patch from your website, as you suggested.
In deed, the "unregistered class" problem disappeared, but was unfortunately replaced by a "unregistered void cast" exception when trying to serialize across shared-object boundaries.
All classes are registered using BOOST_CLASS_EXPORT in their respective .cpp file, yet I can't get it to work. I attached a piece of my code to this email. The attached archive contains the following files:
- Classifier.h - Classifier.cpp - Labels.h - Labels.cpp
The class CClassifier has a field labels of type CLabels. The classes are contained in two separate shared-objects. When trying to serialize an object of type CClassifier, an exception gets thrown when attempting to serialize the field labels. Any ideas?
Best regards,
Christian Widmer
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Christian Widmer
-
Jerry
-
Robert Ramey