When I have an abstract base class foo
, defined in libX.a
class foo {
virtual void bar() = 0;
};
... and a derived class foo_impl
, defined in libY.a
class foo_impl : public foo {
void bar() { /* do something */ }
};
... and use both libraries to link a program -lX -lY
int main() {
foo* my_foo = receive_a_foo_from_somewhere();
my_foo->bar();
}
Then
- how can I force the linker to actually link the symbol referring to
foo_impl::bar()
? - does
objdump -t program
listfoo_impl::bar()
when it is correctly linked?
EDIT: to clarify, I am using linux with gcc or clang
EDIT 2: had missed virtual
for bar()
EDIT 4: I apologize for missing clarity. The question should have been "how can I force the linker to actually include foo_impl::bar()
in the executable so it can be resolved at runtime?"