Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Shared libraries / C++

Reply
Thread Tools

Shared libraries / C++

 
 
jon.apostoles@gmail.com
Guest
Posts: n/a
 
      02-21-2005
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?

 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      02-21-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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.

 
Reply With Quote
 
 
 
 
SnaiL
Guest
Posts: n/a
 
      02-21-2005
No, you don't need to link plugin DLL (SO) files with AppCode.
Moreone, you should not do that

 
Reply With Quote
 
Shezan Baig
Guest
Posts: n/a
 
      02-21-2005

(E-Mail Removed) 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-

 
Reply With Quote
 
jon.apostoles@gmail.com
Guest
Posts: n/a
 
      02-22-2005
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 )

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
standard libraries don't behave like standard 'libraries' Sriram Srinivasan Python 13 11-12-2009 06:05 PM
Using mandatory libraries (custom class loading vs. expanding libraries) Karsten Wutzke Java 21 06-29-2007 09:25 PM
JVM and shared libraries Dave Neary Java 13 03-24-2005 04:44 PM
Parsing Native shared libraries thomas.smith@cox.net Java 0 02-18-2005 02:52 PM
Shared libraries on dotnet Tascien ASP .Net 1 07-24-2004 02:59 AM



Advertisments