I am compiling an embedded application for ARM Cortex M4 with arm-none-eabi-g++ version 4.9.3. To make the target image as small as possible, I link the application with -specs=nano.specs
.
Now I encountered a strange problem: When I anywhere in the code define a pure virtual function (an then I define its body in a child class), I get this linking error:
abort.c:-1: Error: undefined reference to `_exit'
sbrkr.c:-1: Error: undefined reference to `_sbrk'
signalr.c:-1: Error: undefined reference to `_kill'
...
This is correct because I really don't have these functions defined in my project because I don't use them at all. But why the compiler need these functions when I want to make a pure virtual function? When I define an empty body to the virtual function, the linker errors are gone. Can somebody explain me the magic behind the pure virtual functions?
EDIT: To make things more clear, here is a very simple example of my code:
class Parent {
public:
virtual int foo() { return -1; } // This compiles normally.
virtual int foo() = 0; // This gives me the linker error above.
}
class Child {
public:
virtual int foo { return 42; }
}
Child test;