- main.cpp <- line 106 to 164 invoke dlopen/dlsym/dlclose
- basefilter.hpp <- naked abstract base class
- basefilter.cpp
- examplefilter.hpp <- a test plugin
- examplefilter.cpp
- everything <- the repository
Running the whole thing will result in the following error:
Cannot open library "./libexamplefilter.so" ./libexamplefilter.so: undefined symbol: _ZTI10BaseFilter
Since the code is pretty small and understandable you should be able to understand it right away.
Anyone a clue what is wrong?
Should I make rather declare create() as extern “C” void* create(void);
and cast the void pointer afterwards instead of directly trying to link c++ symbols?
Next Step
after using -Wl,-export-dynamic, it tells me:
Cannot load library symbols "./libexamplefilter.so" ./libexamplefilter.so: undefined symbol: create
Uh, do I have to give a mangled c++-name there instead of “dlsym(handle, “create”)”. Probably. Is there a elegant way to do this?
The answer is declaring create() extern “C” … create ….
This works perfectly well.
Problem solved. Thanks for your help and patience.
You need to use the linker option “export-dynamic” when compiling your main executable.
Normally, the main executable won’t export its symbols for use by the dynamic linker (unless the symbol is used by some shared library participating in the link), which means that if your library calls back into the main exe, it will fail to load.
This happens implicitly when you try to subclass a class with virtual methods and in some other cases. If you try to do this, it’s a fail.
So when linking your main program, add
-Wl,-export-dynamic, it’ll just work.