Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] Export macro doesnt work
From: Júlio Hoffimann (julio.hoffimann_at_[hidden])
Date: 2011-08-12 20:44:33


Hi Jari,

I had the same frustration with Boost.Serialization these days, i know
exactly what you're thinking: wtf?! This should be easy!

Let me tell you what solved the problem in my case...

Suppose you have a derived class D implemented as usual (D.hpp / D.cpp). You
need to use the two macros mentioned at the end of the files *outside* any
namespace. For instance:

//////////////////////////////D.hppnamespace N{
    class D : public B
    {
        // something
    };} // namespace N

BOOST_CLASS_EXPORT_KEY( N::D )
//////////////////////////////D.cpp#include D.hpp
namespace N{
    // D implementation} // namespace N

BOOST_CLASS_EXPORT_IMPLEMENT( N::D )

You also need to include the boost::archives you're using in D.hpp, since
this is the obscure way Boost.Serialization instantiates code for your
class.

Regards,
Júlio.

2011/8/12 Jari <jaristr_at_[hidden]>

> I'm using 1.46.1.
>
> So I must use EXPORT_KEY and EXPORT_IMPL ?
>
>
>
> On Fri, Aug 12, 2011 at 7:33 AM, Robert Ramey <ramey_at_[hidden]> wrote:
> > Jari wrote:
> >> Ok I tried one test code and it worked, but when I moved the all the
> >> classes in header file and but the export macro in cpp file it fails
> >> with "derived class not registered or exported".
> >>
> >> Then I moved the export macros to main.cpp right before main() and
> >> before the saving/loading calls, and that did the trick.
> >>
> >> So it seems export's need to be in same CPP file where the
> >> loading/saving starts?
> >> Or is it in same cpp where the function is?
> >>
> >> Im using visual studio 10 express
> >
> >
> > The question of export being in the *.ccp and/or in the header
> > was a confusion which has only been resolved in recent
> > versions of the library. Now there is EXPORT_KEY
> > and EXPORT_IMPL... Which resolves the ocnfusion.
> > I don't know which version of boost you're using so
> > I don't know if this addresses your issue or not.
> >
> > Robert Ramey
> >
> >
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
> >
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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