Hi,
When we write a program, usually we use many functions that their definition is not in our file. Instead it is in an external file that is often a .lib or a .dll and after compilation linker will link our program to those files.
For example we have a program:
Code:
#include<iostream.h>
#include<math.h>
void function_ex (int ); //It is a function prototype
void main(){
int a;
cin>>a;
function_ex(a);
}
void function_ex (int b){
cout<<"Square root is:"<<sqrt(b)<<endl;
}
In compilation time, compiler sees the "function_ex" prototype and will find its body in our file too. But what about "cout" or sqrt()? It can't find any declaration about it in this file, but it can see their declarations in included files iostream.h and math.h. But it still can't find the body of these functions or data types so mark them for further regards. The compiler now has done its duty.
Now linker comes and sees these "Unresolved References", it will then search in .dll and .lib files to find the bodies and definitions. Once it found it, it will link the file to that .dll or will copy the codes from lib file to ours. If not found, error occurs. Correct?
Now the question is: How can we find out where the body of sqrt() is? In what dll or which lib? Is there any way to ask linker about them?