[1.44][serialization] Link error with polymorphic archive and BOOST_CLASS_EXPORT

I've run into a conflict between use of the polymorphic archives and the BOOST_CLASS_EXPORT() macro. It doesn't seem possible to use both without getting a link error. The following code illustrates the problem (yes, I know this code doesn't do anything worth doing, but it's the simplest code that demonstrates the problem): ---------------------- # include <sstream> # include <boost/serialization/export.hpp> # include <boost/archive/polymorphic_binary_oarchive.hpp> class A { public: template<class Archive> void serialize(Archive & ar, const unsigned version) { } }; BOOST_CLASS_EXPORT(A); int main() { A a; std::ostringstream os; boost::archive::polymorphic_binary_oarchive oa(os); oa & a; } ----------------------- This code compiles OK, but a link error is generated. I've put the full link error at the bottom of this post; the gist is an undefined reference to: boost::archive::detail::archive_serializer_map<boost::archive::detail::p olymorphic_oarchive_route<boost::archive::binary_oarchive_impl<boost::ar chive::binary_oarchive, char, std::char_traits<char> > >
::erase(boost::archive::detail::basic_serializer const*)
::insert(boost::archive::detail::basic_serializer const*)' /tmp/ccQvudrk.o: In function `boost::archive::detail::pointer_oserializer<boost::archive::detail::pol ymorphic_oarchive_route<boost::archive::binary_oarchive_impl<boost::arch ive::binary_oarchive, char, std::char_traits<char> > >, A>::~pointer_oserializer()': test_boost_ser_main.cpp:(.text._ZN5boost7archive6detail19pointer_oserial izerINS1_26polymorphic_oarchive_routeINS0_20binary_oarchive_implINS0_15b inary_oarchiveEcSt11char_traitsIcEEEEE1AED2Ev[_ZN5boost7archive6detail19
I can make the error go away by either: 1) Commenting out the BOOST_CLASS_EXPORT 2) Changing the type of the oarchive from polymorphic_binary_oarchive to binary_oarchive. It really looks like there's something missing from the serialization library related to the polymorphic oarchive. Thanks in advance for any help. Tim Wilson Full link error: ---------------- /tmp/ccQvudrk.o: In function `boost::archive::detail::pointer_oserializer<boost::archive::detail::pol ymorphic_oarchive_route<boost::archive::binary_oarchive_impl<boost::arch ive::binary_oarchive, char, std::char_traits<char> > >, A>::pointer_oserializer()': test_boost_ser_main.cpp:(.text._ZN5boost7archive6detail19pointer_oserial izerINS1_26polymorphic_oarchive_routeINS0_20binary_oarchive_implINS0_15b inary_oarchiveEcSt11char_traitsIcEEEEE1AEC2Ev[_ZN5boost7archive6detail19 pointer_oserializerINS1_26polymorphic_oarchive_routeINS0_20binary_oarchi ve_implINS0_15binary_oarchiveEcSt11char_traitsIcEEEEE1AEC5Ev]+0x4f): undefined reference to `boost::archive::detail::archive_serializer_map<boost::archive::detail:: polymorphic_oarchive_route<boost::archive::binary_oarchive_impl<boost::a rchive::binary_oarchive, char, std::char_traits<char> > > pointer_oserializerINS1_26polymorphic_oarchive_routeINS0_20binary_oarchi ve_implINS0_15binary_oarchiveEcSt11char_traitsIcEEEEE1AED5Ev]+0x24): undefined reference to `boost::archive::detail::archive_serializer_map<boost::archive::detail:: polymorphic_oarchive_route<boost::archive::binary_oarchive_impl<boost::a rchive::binary_oarchive, char, std::char_traits<char> > >
::erase(boost::archive::detail::basic_serializer const*)'
collect2: ld returned 1 exit status

Wilson Tim-CTW024 wrote:
I've run into a conflict between use of the polymorphic archives and the BOOST_CLASS_EXPORT() macro. It doesn't seem possible to use both without getting a link error. The following code illustrates the problem (yes, I know this code doesn't do anything worth doing, but it's the simplest code that demonstrates the problem):
----------------------
# include <sstream>
# include <boost/serialization/export.hpp> # include <boost/archive/polymorphic_binary_oarchive.hpp>
class A { public:
template<class Archive> void serialize(Archive & ar, const unsigned version) { }
};
///BOOST_CLASS_EXPORT(A); // need only for derived classes
int main() {
A a;
std::ostringstream os(std::ios_binary); // make sure stream is opened binary // boost::archive::polymorphic_binary_oarchive oa(os); boost::archive::polymorphic_oarchive & oa = boost::archive::polymorphic_binary_oarchive(os); oa & a; }
Try the above changes. Robert Ramey

Thanks for the reply. I'm afraid you misunderstood my post. I *know* that BOOST_CLASS_EXPORT is only required for derived classes; and in my actual application, that's certainly what I'm attempting to use it for. The code I posted was just the very simplest code that illustrates the problem, which is (as I said): if I try to use *both* BOOST_CLASS_EXPORT and either of the polymorphic archives, I get a link error. Please try compiling my simple example, *with* the BOOST_CLASS_EXPORT() in there, and see what you get. P.S. Thanks for the suggestion on opening the ostringstream "binary". -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Robert Ramey Sent: Friday, January 21, 2011 5:08 PM To: boost@lists.boost.org Subject: Re: [boost] [1.44][serialization] Link error with polymorphicarchiveand BOOST_CLASS_EXPORT Wilson Tim-CTW024 wrote:
I've run into a conflict between use of the polymorphic archives and the BOOST_CLASS_EXPORT() macro. It doesn't seem possible to use both without getting a link error. The following code illustrates the problem (yes, I know this code doesn't do anything worth doing, but it's the simplest code that demonstrates the problem):
----------------------
# include <sstream>
# include <boost/serialization/export.hpp> # include <boost/archive/polymorphic_binary_oarchive.hpp>
class A { public:
template<class Archive> void serialize(Archive & ar, const unsigned version) { }
};
///BOOST_CLASS_EXPORT(A); // need only for derived classes
int main() {
A a;
std::ostringstream os(std::ios_binary); // make sure stream is opened
binary // boost::archive::polymorphic_binary_oarchive oa(os); boost::archive::polymorphic_oarchive & oa = boost::archive::polymorphic_binary_oarchive(os); oa & a; }
Try the above changes. Robert Ramey _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Robert Ramey
-
Wilson Tim-CTW024