gcc -o / -O option flags

gcc -o writes the build output to an output file.

gcc -O sets the compiler's optimization level.


gcc -o option flag

Write the build output to an output file.

Syntax

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

Example

myfile.c:

// myfile.c
#include <stdio.h>

void main()
{
    printf("Program run\n");
}

 

Build myfile.c on terminal and run the output file myfile:

$ gcc myfile.c -o myfile
$ ./myfile
Program run
$

 


gcc -O option flag

Set the compiler's optimization level.

option optimization level execution time code size memory usage compile time
-O0 optimization for compilation time (default) + + - -
-O1 or -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 O3 with fast none accurate math calculations ---   + +++

+increase ++increase more +++increase even more -reduce --reduce more ---reduce even more

Syntax

$ gcc -Olevel [options] [source files] [object files] [-o output file]

Example

myfile.c:

// myfile.c
#include <stdio.h>

void main()
{
    printf("Program run\n");
}

 

Build myfile.c on terminal and run the output file myfile:

$ gcc -O myfile.c -o myfile
$ ./myfile
Program run
$

 

 


See also

Write how to improve this page

GCC
RAPID TABLES