tags:

views:

170

answers:

5

i am looking into making a C program which is divided into a Core and Extensions. These extensions should allow the program to be extended by adding new functions. so far i have found c-pluff a plugin framework which claims to do the same. if anybody has any other ideas or reference i can check out please let me know.

+11  A: 

You're not mentioning a platform, and this is outside the support of the language itself.

For POSIX/Unix/Linux, look into dlopen() and friends.

In Windows, use LoadLibrary().

Basically, these will allow you to load code from a platform-specific file (.so and .dll, respectively), look up addresses to named symbols/functions in the loaded file, and access/run them.

I tried to limit myself to the low-level stuff, but if you want to have a wrapper for both of the above, look at glib's module API.

unwind
Another option (at least for linux / GNU) would be to use the gmodule mechanism provided by glib. It builds upon dlopen() bit provides a thin-layer modularization approach.
Shirkrin
Shirkrin, consider posting it as an answer.
Roberto Bonvallet
And HP-UX (at least for the older PA-RISC machines) has shlopen() and friends.
Jonathan Leffler
A: 

Do you need to be able to add these extensions to the running program, or at least after the executable file is created? If you can re-link (or even re-compile) the program after having added an extension, perhaps simple callbacks would be enough?

Thomas Padron-McCarthy
+1  A: 

You can extend your core C/C++ program using some script language, for example - Lua There are several C/C++ - Lua integration tools (toLua, toLua++, etc.)

macropas
+2  A: 

The traditional way on windows is with DLLs. But this kind of obselete. If you want users to actually extend your program (as opposed to your developer team releasing official plugins) you will want to embed a scripting language like Python or Lua, because they are easier to code in.

Dustin Getz
A: 

If you're using Windows you could try using COM. It requires a lot of attention to detail, and is kind of painful to use from C, but it would allow you to build extension points with well-defined interfaces and an object-oriented structure.

In this usage case, extensions label themselves with a 'Component Category' defined by your app, hwich allows the Core to find and load them withough havng to know where their DLLs are. The extensions also implement interfaces that are specified using IDL and are consumed by the core.

This is old tech now, but it does work.

Andy Johnson