COMPILATION SYNTAX

GENERAL SYNTAX: DEBUGGING STAGE

root@dev:~$ gcc -g -c {-Wall | -Werror} {-m32 | -m64} {-O#} sourceFileName.c -o destinationFileName.out

 * the -g adds debugging information to the compiled output.
    - this enabled devs or sre to use a debugger like gdb to step through the
      code line-by-line
 * the -c compiles only and doesn't link.
    - it creates an object file (programName.o), NOT an executable yet.
    
 * -O1 turns on compiler optimization
     - use -O2 or -O3 for more aggressive optimization
        - capital O not zero

GENERAL SYNTAX: PRODUCTION STAGE

root@dev:~$ gcc -c {-Wall | -Werror} {-m32 | -m64} {-O#} sourceFileName.c -o destinationFileName.out

 * do not add debugging symbols on production executables
 
 * the -c compiles only and doesn't link.
    - it creates an object file (programName.o), NOT an executable yet.
    
 * -O1 turns on compiler optimization
     - use -O2 or -O3 for more aggressive optimization
        - capital O not zero

GENERAL SYNTAX: COMBINING MULTIPLE SOURCE FILES

root@dev:~$ gcc -c {-Wall | -Werror} {-m32 | -m64} {-O#} *.c -o destinationFileName.out

 * do not add debugging symbols on production executables
 
 * the -c compiles only and doesn't link.
    - it creates an object file (programName.o), NOT an executable yet.
    
 * -O1 turns on compiler optimization
     - use -O2 or -O3 for more aggressive optimization
        - capital O not zero

Last updated