Boost logo

Boost :

Subject: [boost] [1.44][serialization] Link error with polymorphic archive and BOOST_CLASS_EXPORT
From: Wilson Tim-CTW024 (Tim.Wilson_at_[hidden])
Date: 2011-01-21 17:34:51


(Sorry if this is a duplicate post...I sent it once, didn't see it, so
I'm sending again)

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*)

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> > >
>::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
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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk