There are a number of good text books on compilers (and building them) - I have at least 3 or 4 on my bookshelf; however, this is not a beginner-level subject. There is some good documentation on the GNU web site, especially as related to the GCC (GNU Compiler Collection) tool set. Go to www.gnu.org for more details: http://www.gnu.org/software/gcc/
The compiler is presented with a list of source files to compile (i.e. the ones usually named *.cpp)
For each of those:
The preprocessor goes through and handles the #defines, #includes, etc, changing each individual *.cpp file into a slightly different *.cpp file
The compiler turns each slightly different *.cpp file into a single object file
The linker is now presented with a list of those object files, and also a list of any other object files (i.e. libraries) that it is to work with.
The linker joins all the object files into a single new object file with some extra administrative bits (if it is making a library), or a single executable. It makes sure that every function used does actually have an implementation somewhere in those object files or existing libraries (if it can't find one, you get the famous undefined reference error).