|
Boost Users : |
Subject: Re: [Boost-users] undefined reference to base_object
From: John C (johnc_at_[hidden])
Date: 2010-05-03 11:12:45
I was hoping to avoid upgrading, but in case anyone else ever looks at this,
here is what I did to get it working.
My original code was for the serialization library included with boost
1.36.0 (I think). It continued working in Windows with a few minor tweaks
(through several boost upgrades) until I tried to build in linux. As it
turns out, somewhere along the line the call to serialize a base object from
a derived object changed from this:
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & base_object<MyBaseClass, MyDerivedClass>(*this);
....
}
to this:
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MyBaseClass);
....
}
I think this was the main cause of my problem, and this alone might make it
work in boost 1.40.0.
Since the header file that uses this is in a shared object file that in some
cases cannot have any boost dependencies, I had a forward declaration for
base_object. I had to remove the forward declaration and #def in the
inclusion of the boost export.hpp header for the
BOOST_SERIALIZATION_BASE_OBJECT_NVP macro.
For boost 1.42.0 I also had to add the BOOST_CLASS_EXPORT_KEY and
BOOST_CLASS_TYPE_INFO macros to the header and the
BOOST_CLASS_EXPORT_IMPLEMENT to the source files (and of course get rid of
the BOOST_CLASS_EXPORT (or BOOST_CLASS_EXPORT_GUID depending on what you are
using). See the test files in the boost_1_42_0/libs/serialization/test for
details.
The moral of the story:
If you are upgrading boost versions, don't assume the serialization library
hasn't changed drastically, especially if you are serializing polymorphic
types and even if it works fine in Windows.
Thanks for the help Robert....
Robert Ramey wrote:
>
> I would recommend you look at the1.42 documentation. This resolves a lot
> of
> the confusion about the usage of serialization in DLLS (aka shared
> libraries). The real problem is that when I made the library I didn't
> really consider all the implications of spreading the code accross DLLS
> and
> when I did, some many issues came up it took a while to get it right. I
> think it's correct now. One more iteration and it will be more bullet
> proof.
>
> Robert Ramey
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
-- View this message in context: http://old.nabble.com/undefined-reference-to-base_object-tp28417529p28436304.html Sent from the Boost - Users mailing list archive at Nabble.com.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net