Question

Our project uses boost::serialization to serialize many things. But some types are not correctly registered and when serializing them we get an "unregistered class" error I have narrowed the problem to the BOOST_CLASS_EXPORT_KEY, which, for some types are not generating code. What BOOST_CLASS_EXPORT_KEY does is :

namespace boost {
    namespace serialization {
        template<>
        struct guid_defined< T > : boost::mpl::true_ {};
        template<>
        inline const char * guid< T >(){
            return K;
        }
    } /* serialization */
} /* boost */

All objects that are serialized inherit from a base class called Serializable. Serialization is always done via a pointer to the base class.

This works fine except for one case: There is a class template SerializableList which is a Serializable which holds a list of T

template< typename T>
class SerializableList
{
    ...
    std::vector<T> m_list;

    template<class Archive>
    void serialize( Archive & ar, const unsigned int /*version*/ )
    {
        ar & boost::serialization::base_object<businessObjects::Serializable>(*this);
        ar & mList;
    }
};

in a dedicated cpp and hpp files we then declare each instantiation of this template to boost serialization like this:

hpp:

BOOST_CLASS_EXPORT_KEY( SerializableList<SomeT*> );
BOOST_CLASS_EXPORT_KEY( SerializableList<SomeOtherT*> );
BOOST_CLASS_EXPORT_KEY( SerializableList<AThirdT*> );

cpp:

BOOST_CLASS_EXPORT_IMPLEMENT( SerializableList<SomeT*> );
BOOST_CLASS_EXPORT_IMPLEMENT( SerializableList<SomeOtherT*> );
BOOST_CLASS_EXPORT_IMPLEMENT( SerializableList<AThirdT*> );

But half of these lines do not produce executable code in the final executable! if we put a breakpoint on each of those lines and run, half the breakpoints disappear, those who stay are on the working types (those we can serialize). For instance the breakpoints would stay on SerializableList<SomeT*> and SerializableList<AThirdT*> but not SerializableList<SomeOtherT*>.

Btw, we have also tried to call directly boost::serialization::guid<T>(), and while it works fine for say: boost::serialization::guid<SerializableList<SomeT*> >() which returns the key, it doesn't for boost::serialization::guid<SerializableList<SomeOtherT*> >() which calls the default implementation ...

So is there a compiler bug (we use Visual C++ 2010 SP1), or some good reason for the compiler to ignore some of those specializations?

I forgot to mention, all this code lies in a library, which is linked against the exe project. I've tried with different exe projects and sometimes it works sometimes it doesn't ... the compilation options are the same... I really have no clue what's going on :'(

Was it helpful?

Solution

We found the solution,

One (serializable) class had several SerializableList members, and did not include the file with all the "BOOST_CLASS_EXPORT_KEY" lines.

the other projects which were working didn't use that particular class ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top