Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2008-05-29 13:20:15


In order for this to work, you have to explicitly instantiate the code in
the library/dll. It will
not be instantiated automatically as it is not called from within the
library.

For an example of this take a look at demo_pimple

Robert Ramey

Cyril Picat wrote:
> Hi everybody,
>
> I have just tried a simple example of a class serialization in a DLL
> and did not manage to make it work. I have been using Boost
> serialization since a while but until now I was putting all the
> serialization code in the .hpp. By the way thanks Robert (and Boost)
> for this great library.
>
> I am using MSVC 8.0 and Boost 1.34.1. I have tried the same with Boost
> Serialization 1.36 (head of Boost) without any success.
>
> My test is the following. The class MyClass in declared in a DLL
> boost-example.dll built from Example.cpp. A test program
> Example.t.cpp linked with boost-example.dll try to serialize MyClass
> to an XML archive.
>
> The files are the following:
>
> //////// Example.hpp
> #if _MSC_VER > 1000
> #pragma once
> #endif
>
> // Do NOT include any headers after this point #if
> (defined(__COMPILING_Example_CPP__) && defined(WIN32)) #define
> _LIBSPEC __declspec(dllexport) #else #define _LIBSPEC #endif
>
> class _LIBSPEC MyClass
> {
> public:
> MyClass();
>
> private:
> friend class boost::serialization::access;
>
> template <class Archive>
> void serialize(Archive & ar, const unsigned int version);
>
> std::string m_str;
>
> };

// add the folloing here

#include <boost/archive/xml_oarchive.hpp>

#include <boost/archive/xml_iarchive.hpp>
....

// instanciate the code we want to generate and add tothe library
template MyClass::serialize<boost::archive::xml_oarchive>;

template MyClass::serialize<boost::archive::xml_iarchive>;


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