views:

133

answers:

4

It's very on the Mac to create a loadable plugin as a bundle and make it use symbols in the Host executable. How can this be done on Linux and Windows?

I hear there's -rdynamic on Linux that may come in handy but I'm completely at a loss as far as Windows goes.

The point is to move away from linking both the host and the plugin against a shared library and towards a statically built host.

A: 

You may want to use a slightly different model for Windows. If using a cross platform framework, you should be able to IFDEF this in.

LoadLibrary function allows you to pass the name of a DLL to it as a string. You can then get the address of various functions within the Library by their name and point them at a function pointer.

Tim
Tim, there are no dynamic libraries in this case, I'm trying to move away from using dynamic libraries. Assume that the "plugin" is using dynamic libraries at the moment but they will be rolled into the executable via static linking. The symbols will live in the executable but the plugin DLL will still need to make use of them.
wagerlabs
+1  A: 

A plugin model I often see is to call an initialization function in the plugin, passing it a structure or class that contains function pointers in the host executable.

Zan Lynx
I'd rather not go this way since the number of functions to call can be rather large and may change as well. I'd prefer to let the dynamic linker resolve any symbols that exist in the executable and that the plugin is using. This is trivial on Mac OSX, see link in the original post.
wagerlabs
A: 

Just to make sure I understand, you want to be able to dynamically load and unload plugin DLLs which will automagically resolve symbols that are defined only in the host application, correct? I don't think this is possible under Windows (I don't know about Linux). One option would be to move the host functions into a shared static library that everybody links to, but this probably isn't possible because it needs to provide host-specific functionality. I think the only viable option is Zan's approach.

Luke
A: 

There is a way to accomplish this, apparently, but it relies on a hard-coded dependency to the host executable.

wagerlabs