I have read this and this, however, I still do not get it. Elaboration follows.. (the example below is stolen from the question in which the second link is the answer to - it is tweaked a bit though)
ex. Say I have 3 files
main.cpp
myfunction.cpp
myfunction.hpp
//main.cpp
#include "myfunction.hpp"
void localfunction() {};
int main() {
int A = myfunction( 12 );
...
}
//myfunction.cpp
#include "myfunction.hpp"
int myfunction( int x ) {
retu
rn x * x;
}
//myfunction.hpp
int myfunction( int x );
So the object file created of main.cpp has at least one symbol table.
But will this symbol table contain the symbols localfunction
and myfunction
where it will have the address for localfunction
that could be 0x00233 and instead of an address for myfunction
, it holds a "reference" that serves as a note for the linker that it has to connect this symbol with an address found somewhere else (that is a definition), but only if the compiler can see that there is a definition directly included in the current translation unit?
So like the compiler checks if it can find a definition to the symbol (could also be an object) and if it can, it can directly include an address in the symbol table, but if it cannot find any, it adds a reference/note as the address for the corresponding symbol that the linked has to find the address...
Then when the linking process begins, the linker will search for corresponding addresses that are definitions to the given symbol that has been somewhat marked "has no definition" or what?
This is what I understand so far based on my understanding of different sources (including the wiki article) but I am still really confused about this, cannot see it visually, and the understanding written above is probably off and it should be seen as a question rather than an explanation.
Can anybody help?