I am working on a library with a plugin system that currently works by having a plugin register itself on load. An app links with this library, as does the plugin. When BUILD_SHARED_LIBS=ON
, the plugin loads correctly, but when set to OFF
, it doesn’t crash or fail to load, it just doesn’t get registered.
I believe this is because when the library is static, the app and the plugin each get their own copy of everything, including the map of plugins.
On Linux, one can get around this using weak linkage, but there doesn’t appear to be much support for that in CMake (or on Windows, since it isn’t a standard language feature).
Here is a repository containing a minimal example: https://github.com/alexreinking/cpp-plugin-example
Is there a portable way of allowing an application which uses a static library to load a plugin that uses that library?