Reputation: 2319
In case of having an application that is supported on two different operating systems. There is a specific implementation for each operating system.I would like to know how does the compiler know on which platform it is running so that it compiles implementation X and not Y.
Upvotes: 1
Views: 56
Reputation: 178
Compilers usually take a program written in high level language (e.g., C, Rust, Go) and produce an executable for a specific OS and architecture. If you have a compiler that can support multiple OSes and architectures, then it is likely that you would pass in the appropriate parameters via a command line flag or through some configuration file. The compiler could also try to infer the target OS (assuming the target OS is the same OS that is running the compiler) via environment variables such as "OS" and "PROCESSOR_ARCHITECTURE".
Upvotes: 2
Reputation: 5920
Target platform is determined by compiler using command-line flags, which are provided by the IDE, or developer. For example -m32
flag for gcc, or -mwindow
for MinGW. Complete set of this flags you could see in your compiler documentation.
Upvotes: 2