GCC

Jacer Dabbabi
4 min readFeb 5, 2020

What is GCC ?

The original GNU C Compiler (GCC) is developed by Richard Stallman, the founder of the GNU Project. Richard Stallman founded the GNU project in 1984 to create a complete Unix-like operating system as free software, to promote freedom and cooperation among computer users and programmers.

GCC, formerly for “GNU C Compiler”, has grown over times to support many languages such as C (gcc), C++ (g++), Objective-C, Objective-C++, Java (gcj), Fortran (gfortran), Ada (gnat), Go (gccgo), OpenMP, Cilk Plus, and OpenAcc. It is now referred to as "GNU Compiler Collection".

How do we install GCC ?

For unix operating systems , the GCC is already pre-installed , but for windows operating system users you could either install Cygwin GCC, MinGW GCC or MinGW-W64 GCC :

  • Cygwin GCC: Cygwin is a Unix-like environment and command-line interface for Microsoft Windows. Cygwin is huge and includes most of the Unix tools and utilities. It also included the commonly-used Bash shell.
  • MinGW: MinGW (Minimalist GNU for Windows) is a port of the GNU Compiler Collection (GCC) and GNU Binutils for use in Windows. It also included MSYS (Minimal System), which is basically a Bourne shell (bash).
  • MinGW-W64: a fork of MinGW that supports both 32-bit and 64-bit windows.

What is C language ?

C is an imperative procedural language. It was designed to be compiled using a relatively straightforward compiler to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support. Despite its low-level capabilities, the language was designed to encourage cross-platform programming.

Why do we use C ?

‘C’ is a powerful programming language which is strongly associated with the UNIX operating system. Even most of the UNIX operating system is coded in ‘C’. Initially ‘C’ programming was limited to the UNIX operating system, but as it started spreading around the world, it became commercial, and many compilers were released for cross-platform systems. Today ‘C’ runs under a variety of operating systems and hardware platforms. As it started evolving many different versions of the language were released. At times it became difficult for the developers to keep up with the latest version as the systems were running under the older versions. To assure that ‘C’ language will remain standard, American National Standards Institute (ANSI) defined a commercial standard for ‘C’ language in 1989. Later, it was approved by the International Standards Organization (ISO) in 1990. ‘C’ programming language is also called as ‘ANSI C’.

IEEE-the best 10 top programming language in 2018
IEEE-the best 10 top programming language in 2018

What happens when you type gcc main.c ?

To compile a file means we are going to transform a program written in high level programming languange from source code to object code . The source code must go through different steps before becoming an executable program . When we type and run gcc main.c the program goes through these steps so that we can execute it and these steps consist of preprocessing , compiling , assembling and linking .

  • Preprocessing : The C preprocessor modifies a source code file before handing it over to the compiler . First it performs a series of textual transformations on its input then it provides the ability for the inclusion of header files, macro expansions, conditional compilation , and line control. It is possible to see the effect of the preprocessor on source files directly, using the -E option of gcc. For example, the file below :
$ gcc -E test.c
# 1 "test.c"
const char str[] = "Hello, World!" ;

The -E option causes gcc to run the preprocessor, display the expanded output, and then exit without compiling the resulting source code.

  • Compiling : The compiler will convert files generated by the preprocessor as an input and generate an assembly code . So it converts our C program files into the assembly language
  • Assembling : Now as we know computers can only execute binary codes (0,1) . Assembly code is still not understood by our machine . So we need a converter which can convert this assembly code into the machine code . This converter is the assembler
  • Linking : In computing, a linker or link editor is a computer utility program that takes one or more object files generated by a compiler or an assembler and combines them into a single executablefile, library file, or another ‘object’ file.

So after going through this steps , our executable file is ready and the shell prompt will be in a new line .

How to execute the file ?

To put it simple , we can run the file by typing ./a.out

--

--