I'm trying to create a modular interface in my C project that would allow source files to be built selectively and be added and removed without having to change any of the project's core components. I have searched all of the web for a method on how to do this and cannot find anything.
My guess at this stage, would involve something along the lines of each module having it's own source and header files (module_1.c, module_1.h, module_2.c, module_2.h, etc). Each module would likely have to have a structure containing pointers to the needed functions like:
struct module_def {
char *name;
void (*module_init) (void);
void (*module_shutdown) (void);
};
I believe that an array of these definition structures would then need to be accessible by the core code. I just don't know how to have such an array (or anything similar) be generated automatically using a list of enabled modules without resorting to a messy script that creates a new source file containing a list of all the structures during the build process.
At least, that's how I believe this should work.
Ultimately, I'm looking for a way to create a modular coding interface in C that would allow separate modules (source or object files, it doesn't matter) to be selectively linked during build and called by the main application. This is for an embedded solution so dynamic loading, shared libraries, etc cannot work.