Boost logo

Boost Users :

From: Topi Mäenpää (topi.maenpaa_at_[hidden])
Date: 2005-09-20 06:21:39


Hi,

I think I resolved the issue. The problem is that if the base class A is
defined in the main executable, the dynamically loaded DLL apparently
uses a different address space for the definition. Even if I return a
pointer to A from the DLL, I get an unregistered void cast exception. (I
don't know why. Anyone?) If I define the base class in yet another DLL
that both the main program and the dynamically loaded DLL link to,
serialization works just fine.

Regarding explicit instantiation, I am using polymorphic archives and
I'm registering the class after including the polymorphic archive headers.

By the way, the serialization library has trouble compiling with gcc
3.4.1 on Mandrakelinux 10.1. For some weird reason, namespace resolution
within boost::serialization and its sub-namespaces does not fall back to
the global scope. For example, the following doesn't compile within the
library:

namespace boost { namespace serialization { namespace access {
boost::serialization::make_nvp(...);
}}}

I needed to convert all occurrences of "boost::" to "::boost::".

-Topi-

Robert Ramey wrote:
> 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
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

-- 
Topi Mäenpää
CTO, Intopii
+358 40 774 7749

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