This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Dynamic Loading of Class Implementation at Runtime.
- To: scherrey at proteus-tech dot com
- Subject: Re: Dynamic Loading of Class Implementation at Runtime.
- From: Marat Boshernitsan <maratb at CS dot Berkeley dot EDU>
- Date: 10 Dec 1998 14:06:08 -0800
- Cc: EGCS Development Group <egcs at cygnus dot com>
- References: <366F6850.9A1FA95A@gte.net>
Well, I do it all the time :) My solution is to have an abstract base
class that is compiled together with the application and completely
describes the interface to the class to be loaded. The shared library
subclasses that class, defining all those abstract methods and provides
a single global extern "C" function for creating instances of the
subclass. When the shared library is dlopen()'ed, the creator function
is looked up and is used for producing instances of library class that
are then cast into the base class type and treated the usual way.
HTH,
Marat.
Benjamin Scherrey <scherrey@gte.net> writes:
> I've seen messages in the past that allude to this subject and I've
> searched long and hard for a (somewhat) platform independent mechanism
> to implement this feature but with no success. So... I'm in need of
> information on how to load, at runtime, from a shared library, the
> implementation of a class (or its subclass) and then be able to unload
> it and load a new implementation.
>
> This requires the ability to resolve virtual and non-virtual member
> functions and not just C-type functions which is what has been the big
> problem. My platforms of interest are x86/Linux, SPARC/Solaris 2.6, and
> HP9000/HP/Ux. This is using egcs1.1.1 G++ and later as they come
> available. I understand that different OS's will likely have different
> calls to get at the shared libraries but my main point of interest is
> the resolution of these mangled symbols at runtime.
>
> Appreciate all pointers and information,
>
> Ben Scherrey