Menu-Submenu

GNU Compiler

GNU Compiler (GCC)


  1. GCC Syntax

#gcc [options] [source files] [object files] [-o output file]


  1. GCC Options



options
description
-c
compile source files to object files without linking. Generate object file
-Dname[=value]
define a preprocessor macro
-fPIC
generate position independent code (PIC) for shared libraries
-fpic
generate more efficient code (than -fPIC), if supported by the platform compiler
-glevel
generate debug information to be used by GDB
-g0: no debug information
-g1: minimal debug information
-g : default debug information
-g3: maximal debug information
-Idir
add include directory of header files
-llibname
link with library file (library name without the lib prefix and the .a or .so extensions). Default link shared library (.so), '-static' to link static library
-Ldir
look in directory for library files
-o output_file
write build output to output file
-Olevel
set the compiler's optimization level for code size and execution time.
'optimization level' described in table below.
-shared
generate shared object file for shared library
-Uname
undefine a preprocessor macro
-w
disable all warning messages
-Wall
enable all compiler's warning messages
NOTE: This option should always be used, in order to generate better code.
-Wextra
enable extra warning messages
-g
Generate debugging information
-fpic -shared
No text relocations for shared libraries
-Werror=format-security
Reject potentially unsafe format string arguments
-Werror=implicit-function-declaration
Reject missing function prototypes

Recommened to use


options
optimization level
execution time
code size
memory usage
compile time
-O0
optimization for compilation time (Default)
+
+
-
-
-O1 / -O
optimization for code size and execution time
-
-
+
+
-O2
optimization more for code size and execution time
--
x
+
++
-O3
optimization more for code size and execution time
---
x
+
+++
-Os
optimization for code size
x
--
x
++
-Ofast
O3 with fast none accurate math calculations
---
x
+
+++
+increase , ++increase more, +++increase even more, -reduce, --reduce more, ---reduce even more, x No change