Dynamic libraries problem.
Hello. I'm trying to implement a plugin system for an application. The
application has two parts: a core dynamic library and an executable.
The application uses the dynamic library to work. With these two
pieces, I can write plugins (in theory), which are dynamic libraries
(.so, using linux platform) . My plugin uses the core library. The
problem is the following. I have an structure like this:
(Core dynamic library)
File Plugin.hpp
class PluginsManager : public Singleton<PluginsManager {
PluginsMap plugins_;
bool registerPlugin(const std::string & plugid, PluginPtr p)
{
plugins_[id] = p;
return true;
}
};
#define REGISTER_PLUGIN(pluginid, plugintype, ns) \
const static bool registered##ns##plugintype =
PluginsManager::instance().registerPlugin(pluginid, \
PluginPtr(new plugintype))
(My Plugin)
namespace Plugins {
class MyPlugin : public Plugin {
....
};
}
REGISTER_PLUGIN("MyPlugin", MyPlugin, Plugins);
(main.cpp)
int main()
{
//Loads .so plugin files, which in turn execute REGISTER_PLUGIN
macro for each file and SHOULD
//register plugins
PluginsManager::instance().init();
//This won't work. I registered the plugin when loaded the dynamic
library, but it doesn't work at all.
//The plugin is not in the container
PluginsManager::instance().getPlugin("MyPlugin")->init();
}
When I try to access the plugin (the dynamic library is CORRECTLY
loaded, and LD_LIBRARY_PATH is correctly set) it seems as if the
instance I am accessing from the main program were different from the
instance in which I register the plugin. Can anyone help? Maybe is a
link or order of initialization problem? Thanks for your time. This is
making me crazy.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]