"listigerBiber" <c.********@urz.uni-heidelberg.de> wrote...
i want to extend a program of mine with a plugin architecture.
I can load and use the shared libs which are implementations of a
abstract base class without any problems. But what i need is a
bi-directional interface, the plugins have to acess objects of the
main programm (pointers to them are passed at plugin initialisation).
This works too - but only if i include the header and .cpp files of
these api objects into every plugin - and that is bloated bullshit !
is there a way to include the api .h files only and uses the
implementation code from the main-application (gcc 3.2 linux 2.4) ??
if i try to do that library loading fails with unresolved symbols
....
What you need is to provide an SDK to the writers of plug-ins. You
have determined what classes plug-ins need, now you have to expose
those classes. The most convenient way is to create "pure abstract"
interfaces. The real objects that will do the work you will create
on demand in some kind of factory function. The plug-ins will call
your factory or will receive the pointers to base classes some other
way, then will call the methods of those base classes, which will
resolve in calls to the implementations through polymorphism.
So, you basically on the right track. Simply extract the interface
the plug-ins will use into the base class, declare those functions
virtual and pure. Make your classes derive from those interfaces,
create the instances of your classes and pass the addresses as base
class pointers to plug-ins.
Victor