Re: module manager


Subject: Re: module manager
From: Mike Nordell (tamlin@algonet.se)
Date: Wed May 02 2001 - 04:56:02 CDT


> Anyway, the reason for a C interface and not C++:
> Consider this function compiled by GCC vs G++ (w/o extern "C")
>
> int abi_plugin_init (void);
>
> C-linkage: abi_plugin_init
> C++-linkage: abi_plugin_initFasdwq21332119`12ALLYOURBASEAREBELONGTOUS
>
> So for our resolveSymbol() function
[...]

The way I've solved this in other projects is to define an ABC, i.e. an
interface, with only pure virtual functions. The shared library the exports
one or two functions with C linkage: create and possibly destroy (names have
been changed to protect the innocent).

The create function returns a pointer to an instance of a class implementing
that interface. Example:

// for app to use
class interf
{
public:
    virtual void vfunc1() = 0;
};

// the following is in the shared library
class foo : public interf
{
public:
    virtual void vfunc1(); // implemented by shared library
};

extern "C" {
interf* create();
}

Replace EXPORT_DIRECTIVE with __declspec(dllexport) for MSVC, whatever is
suitable for gcc.

This way no one ever is concerned how the C++ name mangling is done.

Just to display _one_ way to do this. there are other ways, but they all
depend upon well-defined abstract base class interface.

/Mike



This archive was generated by hypermail 2b25 : Sat May 26 2001 - 03:51:00 CDT