Boost logo

Boost Users :

Subject: [Boost-users] [serialization] problem using BOOST_CLASS_EXPORT macro in a static library
From: Renaud Lepere (Renaud.Lepere_at_[hidden])
Date: 2009-02-10 12:19:34


I have some problems with BOOST_CLASS_EXPORT macro, it
seems that this macro have no effect if i put it in
a separate .cpp file of a static library.

I have a simple class Element that contains a pointer to a
curve that can be of different types (geom2d.hpp).

struct Curve
{
    Curve() {};
    virtual ~Curve() {};
};
struct Line : public Curve
{
    Line(int y = 0): m_y(y) {};
    int m_y;
};

typedef boost::shared_ptr< Curve > CurvePtr;
struct Element
{
    Element(const CurvePtr & curve):
        m_curve(curve) {}
    boost::shared_ptr< Curve > m_curve;
};

I would like to be able to serialize Element, so i
wrote a serialize.hpp file (attached) containing code for
serializing those structures.

I also wrote export.cpp using

#include "geom2d.hpp"
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include "serialize.hpp"
#include <boost/serialization/export.hpp>
#include <iostream>

BOOST_CLASS_EXPORT(Curve);
BOOST_CLASS_EXPORT(Line);

I put the export.cpp file in a library named geom2d,
but when trying to serialize my structures using something
(attached main.cpp).

        CurvePtr c(new Line(10));
        const Element e(c);
        std::ofstream ofs("filename");
        {
            boost::archive::text_oarchive oa(ofs);
            oa << e;
        }
I received an exception "unregistered class". If i dont
put export.cpp in a library but in the same compilation unit
as main.cpp, the error disappear (visual studio 8.0 and 9.0).

What is the good way of doing this, should i wrote an export.hpp file
containing the macros and include this file in a .cpp of the main
compilation unit ?

Thanks,

Renaud
 








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