Serialization of derived classes with boost 1.34.1
Hello, I have a problem to serialize a derived class. In some classes I use a shared_ptr<A> which acts as a interface for some other classes. Til now I had the implementation in the header and it worked fine with the BOOST_CLASS_EXPORT(B) declaration after at the end of the header file where B was defined. For performance reason (compile time) I have moved the serialization code from the header file (there is only the declaration) to the .cpp file (now I use also only the polymorphic_binary_archive). There I have also the declaration for the polymorphic_binary_archive template void B::serialize(boost::archive::polymorphic_iarchive& ar, const unsigned int file_version); template void B::serialize(boost::archive::polymorphic_oarchive& ar, const unsigned int file_version); After linking I have now some linker errors. First for the class B which is derived from A and for the class A. All linker errors use the binary_archive. If I declare the "BOOST_CLASS_EXPORT(B)" at the end in the .cpp file I get only an linker error for class A. How I can solve this? Best regards Hansjörg
It may help is you give some sample code. Presently there are too many
unknown(s) to give an accurate answer. I have some speculations;
1.) You may want to take a look at the test_no_rtti.cpp example for more
details. $BOOST_ROOT/libs/serialization/test
2.) You could check the docs on EXPORT && TYPE_INFO as well.
Cheers,
Tim
On Thu, Aug 21, 2008 at 5:01 AM, Hansi
Hello,
I have a problem to serialize a derived class. In some classes I use a shared_ptr<A> which acts as a interface for some other classes.
Til now I had the implementation in the header and it worked fine with the BOOST_CLASS_EXPORT(B) declaration after at the end of the header file where B was defined.
For performance reason (compile time) I have moved the serialization code from the header file (there is only the declaration) to the .cpp file (now I use also only the polymorphic_binary_archive). There I have also the declaration for the polymorphic_binary_archive
template void B::serialize(boost::archive::polymorphic_iarchive& ar, const unsigned int file_version); template void B::serialize(boost::archive::polymorphic_oarchive& ar, const unsigned int file_version);
After linking I have now some linker errors. First for the class B which is derived from A and for the class A. All linker errors use the binary_archive.
If I declare the "BOOST_CLASS_EXPORT(B)" at the end in the .cpp file I get only an linker error for class A. How I can solve this?
Best regards Hansjörg
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Regards, Timothy St. Clair [timothysc@gmail.com]
Probably something else needs to be explicitly instantiated. Perhaps template void A::serialize(boost::archive::polymorphic_iarchive& ar, const unsigned int file_version); template void A::serialize(boost::archive::polymorphic_oarchive& ar, const unsigned int file_version); Look at the demos. One of them addresses this problem - though not through shared_ptr. Robert Ramey Hansi wrote:
Hello,
I have a problem to serialize a derived class. In some classes I use a shared_ptr<A> which acts as a interface for some other classes.
Til now I had the implementation in the header and it worked fine with the BOOST_CLASS_EXPORT(B) declaration after at the end of the header file where B was defined.
For performance reason (compile time) I have moved the serialization code from the header file (there is only the declaration) to the .cpp file (now I use also only the polymorphic_binary_archive). There I have also the declaration for the polymorphic_binary_archive
template void B::serialize(boost::archive::polymorphic_iarchive& ar, const unsigned int file_version); template void B::serialize(boost::archive::polymorphic_oarchive& ar, const unsigned int file_version);
After linking I have now some linker errors. First for the class B which is derived from A and for the class A. All linker errors use the binary_archive.
If I declare the "BOOST_CLASS_EXPORT(B)" at the end in the .cpp file I get only an linker error for class A. How I can solve this?
Best regards Hansjörg
Robert Ramey schrieb:
Probably something else needs to be explicitly instantiated. Perhaps
template void A::serialize(boost::archive::polymorphic_iarchive& ar, const unsigned int file_version); template void A::serialize(boost::archive::polymorphic_oarchive& ar, const unsigned int file_version);
Look at the demos. One of them addresses this problem - though not through shared_ptr.
Robert Ramey
I have class A explicitly instantiated. The strange thing is that the linker error is allways that I don't have a instantiation with binary_oarchive and binary_iarchive. I think it has something to do, that in some other project headers the binary_oarchive is used and for that the BOOST_CLASS_EXPORT(B) makes also a definition for binary_oarchive(Regarding to the documentation an autodetect of the included headers is made). But why this has influences on the definitions for A? Best regards Hansjörg
participants (3)
-
Hansi
-
Robert Ramey
-
Tim St. Clair