0

I have written a DLL. I want to register plugins in my project.

This is how the plugin manager looks like:

extern "C" class PluginManager
{
private:
    list<IPlugin*> pluginRegistry;

public:
     PluginManager();
     void registerPlugin(IPlugin * plugin);
     list<IPlugin*> getPlugins();
     void loadPlugins();
     virtual ~PluginManager();
protected:
};

and this is my library:

#include "PluginManager.h"
#include "BinFilter.cpp"
#include "BoxFilter.cpp"
#include <list>

extern "C" void RegisterPlugins(PluginManager * manager){
    manager->registerPlugin(new BoxFilter);
    manager->registerPlugin(new BinFilter);
}

But I have an error:

./src/plugins/lib1.so: undefined symbol: _ZN13PluginManager14registerPluginEP7IPlugin

How to avoid it?

UPD:
System is ubuntu, compiler g++ dlopen opens my file, but an error appear when I try to call IPlugin method dlopen and dlsym called this way :

  char * newName = (char *) calloc(strlen(entry->d_name)+14, 1);
  strcpy(newName, "./src/plugins/");
  strcat(newName, entry->d_name);
  void * h = dlopen (newName, RTLD_NOW) ;


 #typedef FUNCTION = "RegisterPlugins"; 
 typedef void (*func_t)(PluginManager *);  
 func_t func = (func_t) dlsym(h, FUNCTION); 

UPD:

I found out what the problem was. I closed library before calling function from it.

Elena
  • 1
  • 2
  • remove `extern "C"` from class declaration, why did you put it there? – Slava Oct 07 '15 at 13:34
  • 3
    What operating system? What compiler? It is likely a shared object, not a DLL (which exist only on Windows)? How did you compile & link the main program? the plugin? How did you load your plugin (what arguments to `dlopen`, `dlsym`)? Please **edit your question** to improve it! – Basile Starynkevitch Oct 07 '15 at 13:40
  • Possible duplicate of http://stackoverflow.com/q/9759880/416224 – Kijewski Oct 07 '15 at 13:44
  • @Kay: I don't think so. I imagine the main program might have been linked without `-rdynamic` on Linux, but I could be wrong. – Basile Starynkevitch Oct 07 '15 at 14:06
  • @BasileStarynkevitch, I was not sure either, that's why I made it a comment, not a vote. :) – Kijewski Oct 07 '15 at 14:09
  • I voted to close this question, since Elena T did not improve it. – Basile Starynkevitch Oct 07 '15 at 14:18
  • extern "C" was added everywhere as it didn't work and I tried to do something – Elena Oct 08 '15 at 07:21
  • System is ubuntu, compiler g++ – Elena Oct 08 '15 at 07:22
  • dlopen opens my file, but an error appear when I try to call IPlugin method – Elena Oct 08 '15 at 07:29
  • How do you compile and link your plugin, and the main program which loads the plugin? What compiler and linker flags are you using? How do you call `dlopen` and `dlsym`? What flags and arguments do you have? Can you please try to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve) and show us? – Some programmer dude Oct 08 '15 at 07:49
  • Also, please *edit your question* to add relevant information, don't put it in comments. And also please add *all* relevant information asked for. – Some programmer dude Oct 08 '15 at 07:54
  • The problem is that I make a graphics interface. When the program stats working I have to register plugins. And while the window is opened user may add some .so in the folder and press button reload. So I don't think I may compile libraries and main.cpp together – Elena Oct 08 '15 at 07:57

0 Answers0