Chaitu Tech Bits

what is the gcc compiler and what is the use of gcc compiler

Friday, January 21, 2011



The original author of the GNU C Compiler (GCC) is Richard Stallman, the founder of the GNU Project.

The GNU Project was started in 1984 to create a complete Unix-like operating system as free software, in order to promote freedom and cooperation among computer users and programmers. Every Unix-like operating system needs a C compiler, and as there were no free compilers in existence at that time, the GNU Project had to develop one from scratch. The work was funded by donations from individuals and companies to the Free Software Foundation, a non-profit organization set up to support the work of the GNU Project.
The first release of GCC was made in 1987. This was a significant breakthrough, being the first portable ANSI C optimizing compiler released as free software. Since that time GCC has become one of the most important tools in the development of free software.
A major revision of the compiler came with the 2.0 series in 1992, which added the ability to compile C++. In 1997 an experimental branch of the compiler (EGCS) was created, to improve optimization and C++ support. Following this work, EGCS was adopted as the new main-line of GCC development, and these features became widely available in the 3.0 release of GCC in 2001.
Over time GCC has been extended to support many additional languages, including FORTRAN, ADA, Java and Objective-C. The acronym GCC is now used to refer to the "GNU Compiler Collection". Its development is guided by the GCC Steering Committee, a group composed of representatives from GCC user communities in industry, research and academia.



This section describes some of the most important features of GCC.
First of all, GCC is a portable compiler--it runs on most platforms available today, and can produce output for many types of processors. In addition to the processors used in personal computers, it also supports microcontrollers, DSPs and 64-bit CPUs.
GCC is not only a native compiler--it can also cross-compile any program, producing executable files for a different system from the one used by GCC itself. This allows software to be compiled for embedded systems which are not capable of running a compiler. GCC is written in C with a strong focus on portability, and can compile itself, so it can be adapted to new systems easily.
GCC has multiple language frontends, for parsing different languages. Programs in each language can be compiled, or cross-compiled, for any architecture. For example, an ADA program can be compiled for a microcontroller, or a C program for a supercomputer.
GCC has a modular design, allowing support for new languages and architectures to be added. Adding a new language front-end to GCC enables the use of that language on any architecture, provided that the necessary run-time facilities (such as libraries) are available. Similarly, adding support for a new architecture makes it available to all languages.
Finally, and most importantly, GCC is free software, distributed under the GNU General Public License (GNU GPL). This means you have the freedom to use and to modify GCC, as with all GNU software. If you need support for a new type of CPU, a new language, or a new feature you can add it yourself, or hire someone to enhance GCC for you. You can hire someone to fix a bug if it is important for your work.
Furthermore, you have the freedom to share any enhancements you make to GCC. As a result of this freedom you can also make use of enhancements to GCC developed by others. The many features offered by GCC today show how this freedom to cooperate works to benefit you, and everyone else who uses GCC.

Now once I have written the program, I have to compile it. Compilation is the process of converting human readable code into a form which the machine can understand. So to compile the above program, I give the command as follows:
$ gcc test.c
And if there are no syntax errors, the program will be successfully compiled and the compiler will create an executable file called a.out. Now to run our program, we have to execute a.out executable file.
$ ./a.out
As you can see I have used a ./ in front of a.out file. This is necessary if your current directory is not included in the PATH environment variable.

But if you want the compiler to give a different name to the executable file it generates, then you use the -o switch:
$ gcc -o test test.c
This will create an executable file by name 'test' instead of a.out .
But sometimes it is necessary to get an assembly code listing of ones program. This is desirable if we need to say, get an idea of the values stored in the registers. This is also possible in gcc using the '-S' switch.
$ gcc test.c -S -g
What it does is it creates a text file called test.s which contains the assembly code of our program. The -g flag is optionally used to produce debug symbols and line number information.

You can optimize the compiler using the -O flag followed immediately by a number (between 0 and 3) which states the level of optimization. It is good to optimize ones programs as it results in faster binaries.
$ gcc -O2 -o test test.c 
It is worth noting that one can turn off the optimization by using the -O0 switch.

For C++ programs, the gcc suite has another compiler by name g++. All the options which have been explained above works with the g++ compiler too.
Note: The steps detailed above are more useful for C/C++ developers and students interested in learning to program in C/C++ rather than users of Linux. This is because the compiling of source code is made simple in GNU/Linux by the use of the 'make' command.


Source file (pre processer)

pre_processed code (compiler)


assembely code (as)


relocatable code (linkers)


executable code

gcc it is nothing but combination of tools the target config i386 linux



Share/Bookmark

Related Posts Plugin for WordPress, Blogger...