Ok, I thought that BOOST_CLASS_EXPORT will take care of instantiating it. Actually isn't it what is explained in the doc in paragraph 'Exporting Class Serialization'? I am a bit confused and sure I should dive into the Boost.Serialization code to understand more what the macro is doing. The problem with your solution is that I don't want to include any Boost header in Example.hpp. So I have tried the solution from demo_pimpl but it still fail to link with vc 8.0 (there is a comment saying that it fails with vc 7.0)? Is it expected? So I have ended with forward declaring the archives I need in Example.hpp and it works. Though, I would rather but the explicit template instantiation in Example.cpp to keep a clean implementation agnostic header. Is there any way to make this work with VC ? So if anybody is interested, the final Example.hpp is: /////// 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) #define _EXPORT_TEMPLATE template _LIBSPEC #else #define _LIBSPEC #define _EXPORT_TEMPLATE extern template _LIBSPEC #endif namespace boost { namespace archive { class xml_oarchive; class xml_iarchive; }; }; 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; }; _EXPORT_TEMPLATE void MyClass::serializeboost::archive::xml_oarchive(boost::archive::xml_oarchive& ar, const unsigned int version); _EXPORT_TEMPLATE void MyClass::serializeboost::archive::xml_iarchive(boost::archive::xml_iarchive& ar, const unsigned int version); anyway, thanks your your help and your prompt reply. Cyril Picat -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Ramey Sent: Thursday, May 29, 2008 1:20 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [Serialization] Serialization of a class in a DLL 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