Empowering a brighter world through superior education is our commitment.

Online Calculators & Tools

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:


#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.

optionoptimization levelexecution timecode sizememory usagecompile time
-O0optimization for compilation time (default)++--
-O1 or -Ooptimization for code size and execution time--++
-O2optimization more for code size and execution time-- +++
-O3optimization more for code size and execution time--- ++++
-Osoptimization for code size -- ++
-OfastO3 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:


#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
$