Plugin loading library based on Boost DLL
Platform | CI Status |
---|---|
Linux (Focal) | |
Windows | |
Lint (Clang-Format) | |
Lint (CMake-Format) | |
Lint (Clang-Tidy) |
The plugin loader must know the names of the libraries in which to search for plugins. These library names should not contain a prefix (i.e., lib/) or suffix (i.e., .so). The library names can be set in two ways:
- Set the
search_libraries
member directly in code - Add a list of library names to an arbitrary environment variable (separated by colon), and set the
search_libraries_env
member to the name of that environment variable.
The plugin loader must also know the paths in which to look for the specified libraries that contain plugins. These paths can also be set in three ways:
- Set the
search_system_folders
member true. This will allow the plugin loader to look for plugins in directories specified by system environment variables (e.g.,LD_LIBRARY_PATH
). Generally this is the easiest approach. - Set the
search_paths
member directly in code - Add a list of library names to an arbitrary environment variable (separated by colon), and set the
search_paths_env
member to the name of that environment variable
The only requirement for a plugin base class is that it have a member static std::string section
which defines a section name for the plugin and is accessible to the plugin loader class.
The section name is a unique 8-byte string that associates implementations to the base class.
The plugin loader method getAllAvailablePlugins
can identify all symbols in a library with this section name and thereby return all implementations of a particular base class.
It is also generally useful to define a new export macro for the base class that invokes the EXPORT_CLASS_SECTIONED
macro with the section name directly.
See the test plugin base class definition for an example.
Creating an implementation of a plugin is as simple as inheriting from the plugin base class, and calling the EXPORT_CLASS_SECTIONED
macro with the correct section
(or calling a custom export macro defined for the plugin base class, described above). See the test plugin implementations for an example.