Someone could explain to me the three stages of compiling?

Hello,

I stumbled upon this image in the Hello World module of the “Learn C++” course, specifically in the “Compile & Execute” reading. However, Codecademy needs to explain or dive deeper into what a preprocessor and linker are and how they work together to create the executable. For this reason, I would appreciate it if someone explained the three stages of the following image and provided resources for further learning.


Thank you!

Also note: While researching online, I found that there should be four stages and not three; between compiler and linker goes assembler which needs to be added in the previous image.

Hi,

Please note, these are rough guidelines and there are a couple of variations as to how things get categorized. There’s also sometimes a mix-up with the term compilation (for example, Java is an interpreted language, yes it does get “compiled” into byte-code for the JVM but in the end it goes into an interpreter). Strictly speaking compiled languages are things like C, C++, Rust, Haskell, and many others that don’t run on interpreters (but not Java, C#, Python, JS, TS, etc).

Depending on which angle you want to approach the topic from, I recommend either an operating systems reference book or a computer architecture one. If you want to go “deep” into the gory details I’d recommend a compiler book (the famous one is the dragon book, old but still relevant, can probably find it for cheap at thriftbooks.com).

Here’s a good resource for example: Operating System Structures (from the more general set of notes for operating systems: Operating Systems)

I find a useful way to get used to these ideas are to manually compile, link, and load all the way from source to executable to get a sense of the steps. And also try to statically and dynamically link simple libraries to see how that works as well.

2 Likes