Say I have a file called main.h and in there I have some functions declared like
void func();
Then I have a file main.cpp with the definitions. And then finally I have a file called a.cpp which includes main() and just runs all these functions BUT I also have like some variables declared in it like this:
string a = "t";
int b = 2;
Now my question is the linker will combine all this into one executable right? But I mean the variables a
and b
do they get linked to anything? I mean they already have a definition right and somehow all this code gets combined to one executable right? So is it just fair to say the linker also kind of just combines all the code from all 3 files? It sees declarations and finds definitions for them but with these variables and stuff they don't really have anything to link to so does the linker even do anything to them? Or like I said earlier is it correct to say that the linker basically combines all this code together?