I want to have a plugin, with a simpler name to resolve in other C++ code.
class B {
};
extern "C" B foo(); // to avoid name mangling in order to be loaded by dlsym
And in the other part of the program (which is also in C++ and shares the same definition of class B with the plugin):
B (*func)();
func = dlsym("/path/to/so", "foo");
B m = func();
Will such code cause any problem, i.e. is it allowed (by standard) to use a C++ class as parameter or return type in an extern "C"
function? It seems to work on my gcc, but what about the others?
dlsym()
takes a handle returned fromdlopen()
, not the pathname of a shared library. – Endeavor