I am trying to learn how the whole build chain works so I can better understand what goes on when I do build/link/compile etc.
One point I am having trouble with is this: If the compiler turns the source into native assembly, why can't the same program run on different OSs? Isn't assembly run directly by the CPU? So the same machine code should run on every OS, as long as it is the same architecture, no? Why not?
EDIT: Most of the answers so far are about calling the OS's APIs. That obviously is a problem. My question is about the straight machine code. Does it get passed straight to the CPU or not? If I wrote a program in assembly, would I still need to compile separately for each OS? (side point: If I used standard c++ cin/cout, is that OS dependent, get compiled to direct assembly I/O, or does the answer depend on the compiler?)