De Wiki de Calcul Québec
Aller à : Navigation, rechercher
Cette page est une traduction de la page GCC et la traduction est complétée à 100 % et à jour.

Autres langues :anglais 100% • ‎français 100%

The GNU Compiler Collection (GCC) is a set of compilers for C (gcc), C++ (g++) and Fortran (gfortran) available for many plateforms, from Microsoft Windows to embedded systems based on ARM.



Richard Stallman started the GNU project in 1984. The main goal of the project was to create a free operating system. To do so, the GNU project first needed a compiler to create softwares from source codes. The first version of GCC was then first released in 1987[1].

Advantages and disadvantages

GCC is a free software available without restriction on its usage. The GCC license is the GNU General Public License.

GCC is the compilator used by most GNU/Linux distributions, such as those used on Calcul Québec servers. It is therefore available on all of our servers. It is also the reference compiler for many open source softwares.

With respect to Clang, used, for example on FreeBSD, compiling with GCC is slower. Some compiling errors may also be cryptic compared to other compilers. With respect to the Intel compilers, the binaries generated by GCC are often slower, but not always.

Compiling options

A list of generic compiling options is available on the page Compiling Code. The full list of options is available on the official website.

Options specific to GCC

Option Description Example
-march=native Enables optimisations specific to the architecture on which the code is compiled, such as SSE instructions for Intel processors.
gcc -march=native ...
-static Link binaries statically (objects and libraries) to the compiled executable.
gcc -static ...
-m64 Creates binaries for a 64 bits environment.
gcc -m64 ...
-flto Enables interprocedural optimizations.
gcc -flto ...
-fopenmp Enables support for OpenMP.
gcc -fopenmp ...
-ffast-math Enables agressive mathematic optimisations which may significantly increase performance, but which do not respect the IEEE standard for mathematic operations.
gcc -ffast-math ...

Recommended options

It is recommended to use options -Wall -O2 -march=native. The -O2 option may be replaced by -O3 which adds some more optimizations. While -O2 almost always performs better than -O1, it is possible that -O3 performs worse than -O2. For more details, see the official website.

Interprocedural optimization

Softwares generally are compiled one source file at a time. Intermediate binaries are then linked together to create the executable. Interprocedural optimization allows a compiler to optimize by using the full syntaxic tree of all source files. To do so, optimization of intermediate representations is done at linking time [2] [3] [4] [5].

To enable interprocedural optimizations with gcc, use the option -flto :

[name@server $] gcc -flto -march=native -O2 -Wall f1.c f2.c  -o f.out

Compiling OpenMP code

To enable OpenMP threadnig, you need to add the -fopenmp option. For example:

[name@server $] gcc -flto -march=native -O3 -Wall -fopenmp f1.c f2.c -o f.out


  1. http://fr.wikipedia.org/wiki/GNU_Compiler_Collection
  2. https://en.wikipedia.org/wiki/Link-time_optimization
  3. http://gcc.gnu.org/onlinedocs/gccint/LTO.html
  4. http://gcc.gnu.org/wiki/LinkTimeOptimization
  5. http://www.phoronix.com/scan.php?page=article&item=gcc_471_lto&num=1
Outils personnels
Espaces de noms

Ressources de Calcul Québec