GCC Compiler
GCC C Compiler flags
-c
gcc -c compiles source files without linking.
Example
gcc -c myfile.c would generate myfile.o object file.
-D
gcc -D defines a macro to be used by the preprocessor.
Example
Build myfile.c and run it with DEBUG defined:
-g
gcc -g generates debug information to be used by GDB debugger.
-g0: no debug information-g1: minimal debug information-g: default debug information-g3: maximal debug information
Example
Build myfile.c on terminal and run gdb to debug:
-I
gcc -I adds include directory of header files.
Example
proj/src/myheader.h:
myfile.c
Build myfile.c without include directory proj/src:
Build myfile.c with include directory proj/src:
-L/-l
gcc -l links with a library file.
gcc -L looks in directory for library files.
Example
For static library file libmath.a use -lmath:
For shared library file libmath.so use -lmath:
-O
Set the compiler's optimization level.
-O0: optimization for compilation time (default)-O1/-O: optimization for code size and execution time-O2: optimization more for code size and execution time-O3: optimization more for code size and execution time-Os: optimization for code size-Ofast:O3with fast none accurate math calculations
-shared
Generate shared object file for shared library.
-w
Disable all warning messages.
-Wall
Enables all compiler's warning messages.