only the main.cpp needs to be compiled |
No, all of your source files need to be compiled, either together or separately, save header files, which are compiled as part of the translation units that include them. The results of such separate compilation is
object code (generally in the form of
.o files), which are collectively passed to the
linker to form the resulting program.
out of all my years writing code in other languages I've never once heard the term "linker". |
https://lmgtfy.com/?q=linker
In effect, compilation is a three-step process: preprocessing, compilation, and linking. There's different ways to break those phases down, but those will do as search keywords.
It's one of those things that I could use that I don't want to write. The information exists in any decent textbook, however, and if you just wanted a language-technical reference, you could read about C++'s
phases of translation at:
https://en.cppreference.com/w/cpp/language/translation_phases
Essentially, it is phases 1-5, 6-8, and 9, that correspond conceptually with the three steps I referenced above.
There's plenty of information on the internet, as well. See, for instance:
https://stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work