* GCC - GNU Compiler Collection
* Current version: 4.9.0 (for this document)
* Supporting languages:
C, C++, Fortran, Objective-C, Objective-C++, Java, Ada and Go
* Front end compilation:
Part of compiler that is specific to programming languages is called front end
* GCC compiler names for particular languages:
C - gcc
C++ - g++
Ada - GNAT
* Supported C standard: Currently support three standards
ANSI C - (ISO standard) C89 and C90 as defined in year 1989 (ANSI C)
and 1990 (ISO).
> For selecting standards use options '-ansi, -std=c90 or -std=iso9890:1990'
> To obtain all the diagnostics required by the standard use option '-pedantic'
or '-pedantic-error'
> Amended standard (AMD1) - C94 and C95; use option '-std=c9899:199409'
>New edition of ISO std - C99; use option '-std=c99 or -std=iso9899:1999'
>C11 - use option '-std=c11 or -std=iso9899:2011"
By default GCC uses extensions to c standards and uses '-std=gnu90 or
-std=gnu99 or -std=gnu11' default is -std=gnu90
* Supported C++ standard:
> -ansi, -std=c++98, -std=c++03, -std=c++11
> By default g++ support '-std=gnu++98' option
* GCC performs following steps after invoking
>Preprocessing: option -E is used to stop after preprocessing stage
>Compilation: option -c is used to just compile the program, and
doesn't run the linker. The output are object files
by the assembler.
>Assembly: -S option is used to stop the compilation stage and
should not assemble.
>Linking
* Kind of output and compilation option (based on file name extensions)
file.c, c source code that must be preprocessed
file.i, c source code that should not be preprocessed
file.h, c header file to be turned into precompiled header
file.C, c source file that must be preprocessed
file.s, assembler code
file.S, assembler code that must be preprocessed
* Specifying input language
Use option -x to specify input language e.g.
-x c : C programming (c-header cpp-output)
-x c++ : C++ programming (c++-header, c++-cpp-output
* Common gcc command line options used
-c : Compile or assemble the source file, but do not link.
The ultimate output is an object file
-E : Stop after preprocessing stage, do not run compiler.
The output is in the form of preprocessed source code
-o filename : Place output in a file
-v : Print the compilation stages on standard output, kind of
verbose like output of compilation process.
-### : Similar to '-v' but print only non-executing data like configure
options, compile path, library path etc
-pipe : Use of pipes to communicate between various stages of compilation.
Use for optimizing compile time where gcc creates lots of temporary
files and to avoid that pipes are used. (uses more RAM)
-wrapper : Invoke all sub-commands under the wrapper program. e.g.
gcc -c a.c -wrapper gdb, --agrs
This invokes all subprograms of gcc under ‘gdb --args’,
thus the invocation of cc1 is ‘
gdb --args cc1
-fplugin=name.so : Load the plugin code in file name.so, shared object
is opened by dlopen by compiler
-fplugin-arg-name-key=value
-fno-builtin
-fno-builtin-function : Do not recognize build in function that do not begin
with '__builtin__' as a prefix
e.g.
#define abs(n) __builtin_abs ((n))
#define strcpy(d, s) __builtin_strcpy ((d), (s))
-g : Produces debugging information
-ggdb : Produces debugging flags used by gdb debugger
* GCC diagnostic message formatting options
-fmessage-length=n : Format error message to n characters
-fdiagnostics-color[never|always|auto] : Use of color in diagnostic messages
* GCC options to request or suppress warnings
-fsyntax-only : Check the code for syntax errors
-fmax-errors=n : Limit the max error messages to n
-w : Inhibit all warnings
-Werror : Make all warnings as errors
-Wfatal-errors : Abort compilation once a first error occurred
-Wpedantic
-pedantic : Issue all warnings demanded by strict c standards
-Wall : Enables all the warnings
-Wextra : enables all extra warning flags like pointer comparison
with int zero etc
-Wformat : Check calls to printf scanf formatting functions to make
sure argument supplied have type appropriate formatting.
Avoid:
1. Grouping of multiple options e.g., -dv is different than -d -v
No comments:
Post a Comment