Plug-Ins using C++

Plug-Ins using C++

Post by root » Sun, 27 Feb 2000 04:00:00



Hi folks,
        I hope I got the right forum for this: im a developer of a new
open-source project (http://threedsia.sourceforge.net) and have a problem
writing plug-ins:
Because we want to use mainly C++ as language I'd like to have C++ plug-ins, or
at least user C++ classes. While we already wrote some plug-ins with C and they
worked fine, I renamed a working plug-in from textonlyFrontEnd.c to *.cpp,
forcing make to use g++ as compiler. Compiles fine, but the resulting library
can't be accessed with dlsym... I already consulted what-ever-doc-I-could-find,
but I've not a suitable solution.
Thnx for any information,
        Marc Haisenko
 
 
 

Plug-Ins using C++

Post by Frank V. Castellucc » Sun, 27 Feb 2000 04:00:00



> Hi folks,
>         I hope I got the right forum for this: im a developer of a new
> open-source project (http://threedsia.sourceforge.net) and have a problem
> writing plug-ins:
> Because we want to use mainly C++ as language I'd like to have C++ plug-ins, or
> at least user C++ classes. While we already wrote some plug-ins with C and they
> worked fine, I renamed a working plug-in from textonlyFrontEnd.c to *.cpp,
> forcing make to use g++ as compiler. Compiles fine, but the resulting library
> can't be accessed with dlsym... I already consulted what-ever-doc-I-could-find,
> but I've not a suitable solution.
> Thnx for any information,
>         Marc Haisenko

One simple framework to use, without knowing what your requirements are,
can be:

1. Define the abstraction of what you expect your plugins to support.
2. Include in the shared library ( I assume ) a extern "C" factory
method for the plugin implementation.
3. The user specifies the library, you load and test for the common
factory method and viola!

For a general idea of what I mean:

// ----------------------------------------------
// In your engine/framework/application/whatever
// ----------------------------------------------

class AbstractPluginInterface
{
public:

   //
   // Bunch of pure virtuals, or virtuals with implementation
   //

Quote:};

class PluginLoader
{
public:

   //...

   AbstractPluginInterface *loadPlugin( pluginIdentifier )
   {
        // load the library identified
        // resolve address of "createPlugin"
        // invoke the factory method
        return (*createFunc)();
   }

Quote:};

//----------------------
//In the plugin library:
//----------------------

class PlugInImplementation : public AbstractPluginInterface
{
public:

   //
   // Implementations of pure virtual or handled interface
   //

Quote:};

extern "C"
{
   //
   // Factory method for plug in
   //

   AbstractPluginInterface *createPlugin(/* intialization stuff if
needed */)
   {
      return new PlugInImplementation(...);
   }

Quote:}

--
Frank V. Castellucci
http://corelinux.sourceforge.net
OOA/OOD/C++ Standards and Guidelines for Linux

 
 
 

Plug-Ins using C++

Post by Stephe » Sun, 27 Feb 2000 04:00:00


C++ mangles names. Use extern "C" {} around your function prototypes. Also, use
"nm" to see what symbols are being exported by your lib.

> Hi folks,
>         I hope I got the right forum for this: im a developer of a new
> open-source project (http://threedsia.sourceforge.net) and have a problem
> writing plug-ins:
> Because we want to use mainly C++ as language I'd like to have C++ plug-ins, or
> at least user C++ classes. While we already wrote some plug-ins with C and they
> worked fine, I renamed a working plug-in from textonlyFrontEnd.c to *.cpp,
> forcing make to use g++ as compiler. Compiles fine, but the resulting library
> can't be accessed with dlsym... I already consulted what-ever-doc-I-could-find,
> but I've not a suitable solution.
> Thnx for any information,
>         Marc Haisenko

 
 
 

Plug-Ins using C++

Post by Jeff Koftino » Thu, 02 Mar 2000 04:00:00



>Hi folks,
>    I hope I got the right forum for this: im a developer of a new
>open-source project (http://threedsia.sourceforge.net) and have a problem
>writing plug-ins:
>Because we want to use mainly C++ as language I'd like to have C++ plug-ins, or
>at least user C++ classes. While we already wrote some plug-ins with C and they
>worked fine, I renamed a working plug-in from textonlyFrontEnd.c to *.cpp,
>forcing make to use g++ as compiler. Compiles fine, but the resulting library
>can't be accessed with dlsym... I already consulted what-ever-doc-I-could-find,
>but I've not a suitable solution.
>Thnx for any information,
>    Marc Haisenko

Check out http://www.jdkoftinoff.com/linux1.html
for an example program using c++ & dlsym and object factories for c++
dynamically loaded plugins.

Best Regards

Jeff Koftinoff

 
 
 

1. Netscape plug-ins on AIX 4

Does anyone know if Netscape supports plug-ins on AIX?  I've a feeling
last time I asked the question they didn't and now they might.

RSVP if you are in the know,

alan
-----------------------------------------------------------------------
 Alan Donovan, FORE Audio & Video, 14 Regent Street, Cambridge CB2 1DB

-----------------------------------------------------------------------

2. Password age code

3. plug-ins netscape

4. Always put Oracle in a zone?

5. Reward for NExS Spreadsheet Plug-Ins

6. serial 'laplink' between 2 PC unusable !

7. Netscape helpers and plug-ins, also java help

8. ramdisk

9. List of plug-ins for linux/netscape please!

10. Browser Question (Plug-ins) m-w.com

11. Netscape and Plug-ins

12. Netscape plug-ins

13. Acrobat Reader 4.0 MIME Type for Netscape plug-ins