Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2007-06-28 11:46:14

I would recommend re-organizing the code slightly as below.

// remove archive headers as they are not an attribute of the class
 class TcpEndpoint : public I_Endpoint
 { ... };

 #include <boost/serialization/export.hpp>
 BOOST_CLASS_EXPORT_GUID(RCF::TcpEndpoint, "RCF::TcpEndpoint")

> ------------------------------------------------------
> ***a.cpp***
> ...
> #include "./TcpEndpoint.hpp"
> ...
> ------------------------------------------------------
> ***b.cpp***
> ...
> #include "./TcpEndpoint.hpp"
> ...
> ------------------------------------------------------
> ***c.cpp***
> ...
> #include "./TcpEndpoint.hpp"
> ...

> "A.h"
> #include <boost/serialization/export.hpp>
> class A : public Base {};


#include <boost/archive/text_oarchive.hpp>
 #include <boost/archive/text_iarchive.hpp>
#inlcude "A.h"
 #inlcude "B.h"
 #inlcude "C.h"

> int main() {...}

This should do it. To summarize.

EXPORT should be considered an attribute of the class so it can/should be in
the class header.

#include <...archive.hpp> is not an attribute of the class so it should NOT
be in the class header. It is used to emit code for each EXPORT ed type for
each archive used. So the combination of and exported type and and archive
should be in one and only one module. If you want to encapsulate the
serialization code - e.g. you're making a library of all the code for all
the types, make a module:


#include <boost/serialization/text_oarchive.hpp>
#include <boost/serialization/text_iarchive.hpp>
...// other archive types here.

#include "a.hpp" // includes EXPORT

template<class Archive>
void a:serialize(Archive ar, const unsigned int version){
    ar & ..;

Now you'll have the serialization code generated for type a and related to
its export key.

Note that the code will be generated regardless of whether its called or
not. SOOOO
I would recommend that you organize your application as a library of
modules. One module
for each non-trivial type you use. The then link your main module against
the library. This
will get you what you want, produce the smallest usable executables, and
minimize compile
and link time.

Good Luck

Robert Ramey

Boost list run by bdawes at, gregod at, cpdaniel at, john at