I have a shared object my_lib.cc
that defines in its header a class together with a factory function:
extern Foo* GetFoo():
class Foo {
public:
Foo() {}
virtual ~Foo() {}
};
Now I would like application that uses the library, main.cc
, to contain:
#include "my_lib.h"
class Bar : public Foo {
// ...
};
Foo* GetFoo() {
return new Bar();
}
The point being that when the code inside the shared object needs to create a Foo
it will call the method provided by the application dynamically linking it. Is this possible to do? Typically, an application depends on symbols provided by shared objects, but is it possible to have a shared object depend on a symbol in the binary that dynamically loads it?