Skip to main content
1
GCC Compiler
Presented by: Anil pokhrel
BscCSIT 6th semester
2
Contents
• History of GCC
• Introduction to GCC
• Options in GCC
• Conclusion
History of 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.
4
Introduction to GCC
• Stands for GNU C/C++ Compiler
• A popular console-based compiler for *NIX platforms
and others; can cross-compile code for various
architectures
• gcc to compile C programs;
• g++ for C++
• can actually work with also Java and a couple other
languages
To compile: -c
1. gcc performs compilation and assembly of the source
file without linking.
2. The output are usually object code files, .o; they can
later be linked and form the desired executables.
3. Generates one object file per source file keeping the
same prefix (before .) of the filename.
4. gcc main.c
Options: -o <filename>
• Places resulting file into the filename specified instead
of the default one.
• Can be used with any generated files (object,
executables, assembly, etc.)
• If you have the file called source.c; the defaults are:
• source.o if -c was specified
• a.out if executable
• These can be overridden with the -o option.
• gcc main.c -o main
Options: -g
•Includes debugging info in the generated object code.
This info can later be used in gdb.
•gcc allows to use -g with the optimization turned on (-O)
in case there is a need to debug or trace the optimized
code.
Options: -Wall
• Shows most of the warnings related to possibly incorrect code.
• Wall is a combination of a large common set of the -W options
together. These typically include:
• unused variables
• possibly uninitialized variables when in use for the first time
• defaulting return types
• missing braces and parentheses in certain context that make
it ambiguous
• etc.
Options: -ansi
• For those who are picky about standard compliance
and to ensures the code compiled complies with the
ANSI C standard;
• These options can be quite annoying for those who
don’t know C well since gcc will refuse to compile
unkosher C code, which otherwise it has no problems
with.
• $ gcc -Wall -ansi main.c -o main
Conclusion
Refferences
• https://www.geeksforgeeks.org/gcc-command-in-linux-
with-examples/
• https://www.rapidtables.com/code/linux/gcc.html
• https://en.wikipedia.org/wiki/GNU_Compiler_Collection
• https://www.thegeekstuff.com/2012/10/gcc-compiler-
options/
13