how can a program be OS-dependent? I know the fact that you cannot run the same machine code on two different machines,

so the software must be machine dependent (i.e Arm program cannot run on either powerpc or x86).

but in reality the software is OS dependent (i.e linux programs cannot run on windows or mac).

how does this happen? my best guess for now is that every OS behaves like a virtual machine and the source is compiled for windows-machine,may be??
and this machine has its own assembly code?
Operating systems have Application Programming Interfaces, whose functionalities are available as libraries that are linked to the code produced by the programmer.

This does not mean they constitute virtual machines. They just encapsulate operations that are not directly accessible to the programmer, either because they depend on low level instructions or protocols that are protected, or because they are provided as high-level standard services.

What happens is simply that what you write in a language that compiles to machine code is only a part of what will be running. Usually a very small part.