DEV Community

Discussion on: Explain me C compilation like I'm five

Collapse
 
andreanidouglas profile image
Douglas R Andreani

What is the role of the OS here? Does it interfere with the type of machine code? Does the compiler require to link additional libraries in order to run the program on certain os?

Collapse
 
lpasqualis profile image
Lorenzo Pasqualis

When you compile a program you might have to choose the target system.

Usually, a compiler that runs on a system will compile for that system, but that is not always the case. (For example, you can compile an Arduino sketch on a Mac. The compiler runs on the Mac, but the executable runs on the Arduino.)

Depending on the program, the compiler will most likely have to link your code with OS specific libraries. Some libraries are standard, and always available on all OS's (example: standard IO in C). Using only standard libraries make your code portable to many systems.

Other libraries are not standard and make your code not easily portable to other OSs.