i have given the linker option as below:
linkopt -Wl,--wrap=_ZN4Test5printEP8Unneeded
If i don't include Test.o and Unneeded.o to create the executable, it worked fine. If i include only the Test.o, the executable asks for the definition of sprint() function.
"Test.cpp:(.text+0x19): undefined reference to `Unneeded::sprint()'"
I am wondering that why it asks for the definition of sprint() function, as it won't be called any time (please see that it worked fine, if i don't include test.o and unneeded.o). I am building only the static binary. Please help me to resolve this issue
You are callings junk->sprint(); from Test which you are linking which is why you are receiving the error. If you removed that call from Test you would be ok.