I was reading 'Operating System Concepts' book (Chapter#1) which has a text "By 1991, the GNU operating system was nearly complete. The GNU Project had developed compilers, editors, utilities, libraries and games...". I did not understand why did they develop the 'compiler' for GNU project? Compiler, IMO in simple terms, is a software that converts one source code into, eventually, machine code. So, it makes sense to have compilers targeted for separate hardware e.g. x86, ARM etc. utilizing their native instruction sets.
My question is : Suppose I'm writing a program that has simple mathematical operations like +, -, / and * on INT operands. It does not make any system call (so no dependence on host operating system specs/APIs). I want to release binaries of this rudimentary program for Windows and Mac, which both are using Intel x86 architectures. Do I need to compile my code with different compilers targeted for the host O.S. in which they would be run? If so, why?
I'm asking this question primarily for understanding why did GNU developed its compilers. Any relevant details/references would be of great help.
Thanks.
These are actually two different questions.
Why did the GNU team develop a compiler for their operating system? Because their philosophy was that an operating system is not just a kernel but also includes certain system services and standard applications, including a compiler. Note that your enumeration contains “compilers, editors, utilities, libraries and games”, a selection not based on strict necessity but also deliberate decisions.
“Do I need to compile my code with different compilers targeted for the host O.S. in which they would be run?” You don’t always need different compilers but in most cases¹, you need to create a dedicated binary for each target, even if the targets have the same CPU architecture. This can be done with the same compiler if it supports all your intended targets.
The first reason is that not all operating systems use the same file format. Windows uses PE, Linux uses ELF, for example. The second are calling conventions. Even if your program never invokes a system function (which makes it not very useful, as it can’t produce any result), it is itself a function invoked by the operating system, so it has to adhere to the linking and calling conventions.
¹ some operating systems support plugging in handlers for other file formats