why it is showing add function as a undefined reference.. |
Undefined reference means that whilst the
compiler understands how the function should work (which means it understands the name of the function, the input types and the return type), the
linker cannot find the actual compiled code that actually does the work.
In this case, if you
#include <abc.h>
in your code, the compiler will then find the function prototype, and from that will know the name and parameters. Good so far. Then, everywhere you use the actual function, the compiler effectively leaves a note to the linker, saying "here, you put in the compiled code that actually makes this function call work".
So, then the linker comes along. The compiler has presented it with some compiled code (but NOT the compiled version of abc.cpp, because you have not compiled that, or if you have, you have not told the linker where to find it). The linker then goes looking for the compiled function. It does not find it. It comes back and says "undefined reference". You fix this by compiling
abc.cpp
and making sure the linker can find it.
Under g++, this would be done simply:
g++ main.cpp abc.cpp
to build.
Under Turbo C++, who knows how it's done. The above, though, is a simple explanation of your problem.