if function definition is not available and only the function prototype is externed in header files, then g++ compiler wont give any errors. but during linking, g++ linker will identify the error and says "undefined reference" to corresponding fn. i don't care abt fn definition. i just want to get the binary image and whenever corresponding fn called from that image, then that time only i want to crash. may i know the linker flags to suppress this "undefined reference" linker error?. In VC++, there is a options called /FORCE. is there any similar flags?
1
votes
1 Answers
2
votes
It's completely undefined behaviour, but if you want a crash ...
If you have an undefined symbol such as a function void h()
then its mangled name will be _Z1hv
, so if you define a symbol that name and external linkage it will be found, even if the type is wrong:
int _Z1hv = 0;
void h();
int main()
{
h();
}
This will link, but crash at run-time because the call to h()
will try to "run" a function at the address of the integer variable.
Doing this is wrong and disgusting and kills kittens.