Boost logo

Boost Users :

From: __PPS__ (i-love-spam_at_[hidden])
Date: 2005-12-06 02:16:10


Robert Ramey wrote:
> It SHOULD work but this is an area still in flux.
>
> You might expand on the explanation of how it fails:

It throws "unregistered class", but when I use it as statically linked
lib then everything works as expected.

> Some observations:
>
> There should be no need to include the header
> <boost/serialization/serialization.hpp>
>
> The serialization code will be instantiated only when code like ar <<
> session_record
> is encountered. Since your DLL code doesn't include your any archives no
> code
> is generated.

Yes, there's no need to include <boost/serialization/serialization.hpp>,
it could be removed from the export.h, but it doesn't mean that my DLL
code doesn't include archives' code. Inside implementation of this
(de)serialize functions (somewhere inside export.cpp, or whatever) I
include all the archives code etc.

basicly, here's export.cpp
/////
//all needed includes & using namespace ...

#include "export.h"
session_record::~session_record(){}
session_record::operator session_record *(){
        return this;
}

void serialize(session_record* derived, const char* file_name){
        ofstream out(file_name);
        if(!out || !out.is_open()) throw std::runtime_error(std::string("failed
to open \"")+file_name+'"');
        text_oarchive oa(out, no_header | no_codecvt);
        oa & derived;
}
session_record* deserialize(const char* file_name){
        ifstream in(file_name);
        text_iarchive ia(in, no_header | no_codecvt);
        session_record *derived;
        ia & derived;
        return derived;
}
/////////

then in another app, that links to export.dll I have:
/// needed includes & using declarations ...
#include "export.h"

class client_record : public virtual session_record {
   friend class boost::serialization::access;
   template<class Archive> void serialize(needed args...){
     serialization::base_object<session_record>(*this);
     ar & name;
     ar & address;
     ar & amount;
   }
   virtual void print_on(std::ostream &os)const{
     os <<
     "client record: \n"
     "\tname: " << name << "\n"; //....
   }
public:
   std::string name, address;
   double amount;
};
BOOST_CLASS_EXPORT(client_record);

main()try{

   client_record x;
   x.name = "John Doe";
   x.amount = 129.99;
   x.address = "2080 Wellington, apt. 13";
   serialize(&x, "xxx.txt");

}catch (const exception &e) {
   cout << "error: " << e.what() << endl;
}

/////////

I get unregistered class exception. I use vc71 and if I now in settings
for the export.dll change project type from Dll to static library, and
recompile my test program, everything works as expected.
and this error I get is from serializing from base pointer, not from
deserializing...

>
> The first step to making this work is to look at the demo which
> compiles serialization code in separate modules. This shows
> how to instantiate the required code. Also look at
> polymorphic archives which permit application
> code to be compiled to a common interface.
>


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