Shared libraries / C++

Discussion in 'C++' started by jon.apostoles@gmail.com, Feb 21, 2005.

  1. Guest

    I have a program that is going to have plugins used for various
    capabilities. The main program creates a class (AppCore) which handles
    everything. This class contains another class (PluginController) that
    handles loading the shared objects via the dl* functions. When I
    create the plugins, I link them using -shared.

    The plugins themselves are derived from a class (Plugin)... inside of
    the Plugin class there is a variable to hold a pointer back to the
    AppCore object. This is so the plugins can call various functions from
    AppCore object created at start up.

    Should I have to link in the AppCore.o the plugins when I'm creating
    them? It seems like it wont work unless I do that.. I'm not sure I
    understand why I need to link those in.. shouldn't the main program
    export those symbols?
    , Feb 21, 2005
    #1
    1. Advertising

  2. Rolf Magnus Guest

    wrote:

    > I have a program that is going to have plugins used for various
    > capabilities. The main program creates a class (AppCore) which handles
    > everything. This class contains another class (PluginController) that
    > handles loading the shared objects via the dl* functions. When I
    > create the plugins, I link them using -shared.
    >
    > The plugins themselves are derived from a class (Plugin)... inside of
    > the Plugin class there is a variable to hold a pointer back to the
    > AppCore object. This is so the plugins can call various functions from
    > AppCore object created at start up. Should I have to link in the AppCore.o
    > the plugins when I'm creating them? It seems like it wont work unless I
    > do that.. I'm not sure I understand why I need to link those in..
    > shouldn't the main program export those symbols?


    No. At least under Linux, the plug-in doesn't have access to any symbols of
    the main program. The usual solution to that is to write a shared library
    that contains everything that both the main program and the plug-in need,
    and then link them both to that library.
    Rolf Magnus, Feb 21, 2005
    #2
    1. Advertising

  3. SnaiL Guest

    No, you don't need to link plugin DLL (SO) files with AppCode.
    Moreone, you should not do that :)
    SnaiL, Feb 21, 2005
    #3
  4. Shezan Baig Guest

    wrote:
    > I have a program that is going to have plugins used for various
    > capabilities. The main program creates a class (AppCore) which

    handles
    > everything. This class contains another class (PluginController)

    that
    > handles loading the shared objects via the dl* functions. When I
    > create the plugins, I link them using -shared.
    >
    > The plugins themselves are derived from a class (Plugin)... inside of
    > the Plugin class there is a variable to hold a pointer back to the
    > AppCore object. This is so the plugins can call various functions

    from
    > AppCore object created at start up.
    >
    > Should I have to link in the AppCore.o the plugins when I'm creating
    > them? It seems like it wont work unless I do that.. I'm not sure I
    > understand why I need to link those in.. shouldn't the main program
    > export those symbols?


    The problem with this is that it introduces cyclic dependencies (bad
    thing). i.e., AppCore depends on PluginController, and
    PluginController depends on AppCore (to pass the pointer to the plugins
    when loaded). You will have something like this:

    ,---------. ,------------------.
    | |------->| |
    | AppCore | | PluginController |
    | |<-------| |
    `---------' `------------------'

    One solution is to have a pure virtual interface (e.g., AppInterface),
    that provides all the methods that plugins would need to call in the
    applications. Have AppCore implement this interface and just pass the
    pointer to AppInterface. That way, your dependency diagram looks like
    this:

    ,---------. ,--------------. ,------------------.
    | AppCore |---->| AppInterface |<----| PluginController |
    `---------' `--------------' `------------------'

    Your linker will thank you for it :)

    Hope this helps,
    -shez-
    Shezan Baig, Feb 21, 2005
    #4
  5. Guest

    Thanks a ton! That's exactly what I was looking for. I implemented it
    using an API class that is included by the core, and the plugins.
    Cyclic dependencies are now gone, and it links the way I want it.

    Thank you very much :eek:)
    , Feb 22, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tascien

    Shared libraries on dotnet

    Tascien, Jul 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    363
    Ken Cox [Microsoft MVP]
    Jul 24, 2004
  2. Dave Neary

    JVM and shared libraries

    Dave Neary, Jun 9, 2004, in forum: Java
    Replies:
    13
    Views:
    1,183
  3. Replies:
    0
    Views:
    334
  4. Karsten Wutzke
    Replies:
    21
    Views:
    907
    Roedy Green
    Jun 29, 2007
  5. Sriram Srinivasan
    Replies:
    13
    Views:
    550
    Benjamin Kaplan
    Nov 12, 2009
Loading...

Share This Page