The GNU Compiler Collection (GCC) is a toolkit for compiling and assembling programs for a wide variety of platforms and languages. It is one of the core utilities in the Free Software Foundation's GNU Project.
While it is most closely associated with C and C++, it is in fact a suite of several compilers and their libraries. The newest version of GCC as of 2016-04-27 is version 6.1.0 which includes support for ANSI and K&R C, Objective-C, C++, Java, Fortran and Ada.
GCC is strongly supported on POSIX compliant platforms but has also been ported to other operating systems such as Windows. GCC also includes support for targeting many different CPU architectures including X86, X86-64, IA-64, Alpha, SPARC, MIPS, PowerPC, and ARM.
OS Development with GCC
Although other compilers can be used for OS development, OS developers are encouraged to use one of GCC derivatives.
You need a cross-compiler to compile your operating system, as it will otherwise assume you are building programs for your current operating system, when it really is doing something else.
- Main article: Building GCC
It is worth getting the newest release of GCC and installing it as your system compiler and occasionally upgrading it. It will also help bootstrap a proper cross-compiler.
Creating a GCC Cross-Compiler
- Main article: GCC Cross-Compiler
It is easy and takes a few moments to build a cross-compiler that targets your operating system. It may take a while to build it on slower computers, but you only need to do it once, and you save all the time you would otherwise spend on "fixing" the completely imaginary problems you would encounter otherwise. Later on, when you start building a user-space for your operating system, it is worth creating an OS Specific Toolchain for absolute control of the compiler and to easy compiling user-space programs.
- Main article: OS Specific Toolchain
Once you begin adding a user-space, it's worth setting up a toolchain that understands your operating system and how to produce programs for it. This is the first task when you begin porting GCC.
Hosted GCC Cross-Compiler
- Main article: Hosted GCC Cross-Compiler
This tutorial finishes your OS Specific Toolchain by building it with user-space support.
- Main article: Porting GCC to your OS
You will most certainly want to port GCC if you wish to go self-hosting. It's a bunch of work, but it's not that terribly bad when your operating system becomes ready.
GCC on other systems
GCC comes installed by default on virtually every Unix system. It has also been ported to Windows and other operating systems:
- MinGW is a port of the GNU environment for Windows.
- Cygwin is the choice of most forum members under Windows, hence it is likely to be easier to get help.
- DJGPP is an old port of GCC to DOS and can be used under Windows. Using DJGPP is discouraged.