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.
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.
Options specific to GCC
|-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 ...
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.
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    .
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