Auto-loading of modules is a feature of the CppMicroServices library to manage the loading of modules which would normally not be loaded at runtime because of missing link-time dependencies.
Imagine that you have a module A which provides an interface for loading files and another module B which registers a service implementing that interface for files of type png. Your executable E uses the interface from A to query the service registry for available services. Due to the link-time dependencies, this results in the following dependency graph:
When the executable E is launched, the dynamic linker of your operating system loads module A to satisfy the dependencies of E, but module B will not be loaded. Therefore, the executable will not be able to consume any services from module B.
The problem above is solved in the CppMicroServices library by automatically loading modules from a list of configurable file-system locations.
For each module being loaded, the following steps are taken:
See the ModuleSettings class for details about auto-load paths. The auto-load directory of a module defaults to the module's library name, but can be customized using a
manifest.json file (see Module Properties). For executables, the auto-load directory defaults to the special value
main. This allows third-party modules to be auto-loaded during application start-up, without having to reference a special auto-load directory.
If module A in the example above contains initialization code like
and the module's library is located at
all libraries located at
will be automatically loaded (unless the auto-load paths have been modified). By ensuring that module B from the example above is located at
it will be loaded when the executable E is started and is then able to register its services before the executable queries the service registry.
mainsub-directory of any of the provided auto-load search paths, these modules will then be auto-loaded before your executable's main() function is executed.
The following environment variables influence the runtime behavior of the CppMicroServices library:
;(Windows) separated list of paths from which modules should be auto-loaded.