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

Hi, I discovered a problem, that has been previously discussed in a post from 2011-01-21 which has the same title. No concluding answer was given there, so I post the problem again. Essentially, the following code compiles but doesn't link: -------------------------- #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; } -------------------------- Removing the line with "BOOST_CLASS_EXPORT(A)" or turning the "polymorphic_binary_oarchive" into a "binary_oarchive" removes the linker error. With Visual Studio 10 the following error message occurs: main.obj : error LNK2001: unresolved external symbol "public: static void __cdecl boost::archive::detail::archive_serializer_map<class boost::archive::detail::polymorphic_oarchive_route<class boost::archive::binary_oarchive_impl<class boost::archive::binary_oarchive,char,struct std::char_traits<char> > >
::erase(class boost::archive::detail::basic_serializer const *)" (?erase@?$archive_serializer_map@V?$polymorphic_oarchive_route@V?$binary_oarchive_impl@Vbinary_oarchive@archive@boost@@DU?$char_traits@D@std@@@archive@boost@@@detail@archive@boost@@@detail@archive@boost@@SAXPBVbasic_serializer@234@@Z) 1>main.obj : error LNK2001: unresolved external symbol "public: static bool __cdecl boost::archive::detail::archive_serializer_map<class boost::archive::detail::polymorphic_oarchive_route<class boost::archive::binary_oarchive_impl<class boost::archive::binary_oarchive,char,struct std::char_traits<char> > > ::insert(class boost::archive::detail::basic_serializer const *)" (?insert@?$archive_serializer_map@V?$polymorphic_oarchive_route@V?$binary_oarchive_impl@Vbinary_oarchive@archive@boost@@DU?$char_traits@D@std@@@archive@boost@@@detail@archive@boost@@@detail@archive@boost@@SA_NPBVbasic_serializer@234@@Z)
Is there something wrong with the serialization library? Regards, Ralph Tandetzky.

Ralph Tandetzky wrote:
Hi,
I discovered a problem, that has been previously discussed in a post from 2011-01-21 which has the same title. No concluding answer was given there, so I post the problem again. Essentially, the following code compiles but doesn't link:
-------------------------- #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); boost::archive::polymorphic_archive & poa( oa ); poa & a; } --------------------------
Does it work with the above changes? Robert Ramey

Thanks for your quick reply. But unfortunately it didn't help. I had a little deeper look into the Archive Concept documentation and found the following: http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/archive_referenc... This refers to writing an own archive class and how to avoid compiling, linking and execution failures in case of using the macro BOOST_CLASS_EXPORT(). I checked in the header-file #include <boost/archive/polymorphic_binary_oarchive.hpp> and the work-around using the macro BOOST_SERIALIZATION_REGISTER_ARCHIVE() is implemented there. Still, it might have to do something with that. Do you have any further ideas, how to solve the problem? Ralph Tandetzky. Am 13.08.2011 19:10, schrieb Robert Ramey:
Ralph Tandetzky wrote:
Hi,
I discovered a problem, that has been previously discussed in a post from 2011-01-21 which has the same title. No concluding answer was given there, so I post the problem again. Essentially, the following code compiles but doesn't link:
-------------------------- #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); boost::archive::polymorphic_archive& poa( oa ); poa& a; } -------------------------- Does it work with the above changes?
Robert Ramey
participants (2)
-
Ralph Tandetzky
-
Robert Ramey