I would like to create a program wherein I compile a user interface that has the ability to dynamically load libraries from a .so file. My abstraction class in my user interface program will be programmed to look for the library, but I don't know how to implement that in C++ code, or how to compile my libraries so that I can distribute them as updates without having to re-distribute the binary file.
If anybody has any insight on how to accomplish this, or where I can look for an up to date tutorial (I've seen a few, but they generally refer to C programming), I would appreciate it.
From an object design point of view, you need some abstract interface that the loadable modules implement. Each seperate implementation implements a concrete instance of this interface that does something and provides a factory/creator function that instantiates the class.
From a code partitioning point of view, you put the abstract interface into a common shared library. The app uses it and the pluggable modules use it.
The modules export a single function, the creator function that returns a pointer to the abstract class which is the local concrete instance you need to use.
You can either keep a registry of shared libraries or place them in the same directory. The app picks them up at runtime, loads and calls the creator and uses the returned class.
While this is helpful, I have the interface abstraction in place already, and I plan on plugging the .so files into specified directories.
My question was where I can look to learn how to compile each object (say Impl.h & Impl.cpp) into Impl.so, and from the code in my interface, how to point at the object that's contained in Impl.so.
Hi, I am currently writing an IRC bot that accepts plugins. I reduced the relevant code to a skeleton example. Note that this code uses C++11 for it std::shared_ptr class. If you don't have C++11 then you can use boost or failing that just a raw pointer.
Plugin library header: plugin.h (#include in main program and your plugin code).