
In your dll, are you explicitly instantiating template code for B? This looks like the problem to me. You'll have to use something like: #include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_iarchive.hpp> ... // all the archives you expect to use #include <B.hpp> // B.hpp includes BOOST_CLASS_EXPORT(B) in order to ensure that the required code is generated for the archives you expect to use. Now if you don't want to include serialization code in your dll for a specific set of archive types, you can use polymorphic archive in the DLL. This will use one set of precompiled code (w/o templates) with any of the polymorphic_?archive.hpp used in main. Robert Ramey Topi Mäenpää wrote:
Hi,
How do I register classes that are defined in a dynamically loaded so/dll? Using BOOST_CLASS_EXPORT just causes "terminate called after throwing an instance of 'boost::archive::archive_exception' what(): unregistered void cast". My set-up is as follows:
class A { public: A(); virtual ~A() {} private: // polymorphic archive stuff here };
class B : public A {}
BOOST_CLASS_EXPORT(B);
Serializing instances of B through a A* works fine if B is defined in the main executable. Now, I have tried the following (approximately):
// An exported function that returns a void pointer typedef void* (*func)();
int main() { // Load a dynamic library dll lib = load_dll("mylib.dll"); // Get a pointer to the instance creator function func instance_creator = (func)lib.resolve("instance_creator"); // An instance of B is created in the dll and returned as a void*. A* a = (A*)instance_creator();
...
archive & a; //throws unregistered void cast }
B is both defined and exported in mylib.dll.
So, what is the deal? I don't understand the soul of BOOST_CLASS_EXPORT well enough to solve the problem myself. But since I'm using the dll version of the serialization library, I'd assume that the dynamically loaded dll (mylib.dll) and the main executable use the same address space for the archive classes. I would understand this if I encountered this problem with static linking because I'd need to inlude two copies of the serialization library...
Any advice?
Regards, Topi