Like said Matthieu M. in his comment, there is no native way to get a list of loaded symbols from a dynamic lib.
However, I usually use this workaround, which is to make your plugin declare the symbols in a container, and then to retrieve this container from your main program.
plugin.h
#include <set>
#include <string>
// call this method from your main program to get list of symbols:
const std::set<std::string> & getSymbols();
void MySymbol01();
bool MySymbol02(int arg1, char arg2);
plugin.c
#include "plugin.h"
class SymbolDeclarator {
public:
static std::set<std::string> symbols;
SymbolDeclarator(const std::string & symbol) {
symbols.insert(symbol);
}
};
const std::set<std::string> & getSymbols() {
return SymbolDeclarator::symbols;
}
#define SYMBOL(RETURN, NAME) \
static const SymbolDeclarator Declarator##NAME(#NAME); \
RETURN NAME
SYMBOL(void, MySymbol01)() {
// write your code here
}
SYMBOL(bool, MySymbol02)(int arg1, char arg2) {
// write your code here
}
I only see 2 issues with this solution:
- to have a non-const static variable:
symbols
declared
in plugin.c -> non thread-safe.
- to have code executed before the
main(), which is hardly debuggable.