I was trying to see how virtual functions are compiled and it seem I cannot compile a trivial example to a dylib on macOS.
I've been through countless permutations of this code and SO answers but I cannot get this trivial example compile (or rather link) with:
clang -dynamiclib -o test.dylib test.cc
here is the code:
class Animal {
public:
virtual void who(){};
};
class Cat : Animal
{
public:
virtual void who();
};
void Cat::who() {
}
and here is the complete error:
clang -dynamiclib -o test.dylib test.cc
Undefined symbols for architecture x86_64:
"vtable for __cxxabiv1::__class_type_info", referenced from:
typeinfo for Animal in test-be905f.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for __cxxabiv1::__vmi_class_type_info", referenced from:
typeinfo for Cat in test-be905f.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)