๐ŸŒ
GNU
gcc.gnu.org
GCC, the GNU Compiler Collection - GNU Project
The GNU Compiler Collection includes front ends for C, C++, Objective-C, Objective-C++, Fortran, Ada, Go, D, Modula-2, COBOL, Rust, and Algol 68 as well as libraries for these languages (libstdc++,...). GCC was originally written as the compiler for the GNU operating system.
Installing GCC
The latest version of this document is always available at https://gcc.gnu.org/install/. It refers to the current development sources, instructions for specific released versions are included with the sources.
GCC mirror sites
If you limit access to your mirror ensure the gcc.gnu.org subnet is granted access.
GCC Releases
GCC releases may be downloaded from our mirror sites.
Downloading GCC
The source distribution includes the Ada, C, C++, Objective-C, COBOL (GCC 15 and later), D (GCC 9 and later), Fortran, Go, Modula-2 (GCC 13 and later) and Algol 68 (GCC 16 and later, experimental) compilers, as well as runtime libraries for C++, Objective-C, COBOL, Fortran and Algol 68.
optimizing compiler produced by the GNU Project, key component of the GNU tool-chain and standard compiler for most projects related to GNU and the Linux kernel.
GCC_10.2_GNU_Compiler_Collection_self-compilation.png
gcc 11 1 0 compiling chicken screenshot
The GNU Compiler Collection (GCC) (formerly GNU C Compiler) is a collection of compilers from the GNU Project that support various programming languages, hardware architectures, and operating systems. The Free Software Foundation โ€ฆ Wikipedia
Factsheet
Original author Richard Stallman
Developer GNU Project
Initial release March 22, 1987; 38 years ago (1987-03-22)
Factsheet
Original author Richard Stallman
Developer GNU Project
Initial release March 22, 1987; 38 years ago (1987-03-22)
๐ŸŒ
GNU
gcc.gnu.org โ€บ onlinedocs โ€บ gcc
Top (Using the GNU Compiler Collection (GCC))
This manual documents how to use the GNU compilers, as well as their features and incompatibilities, and how to report bugs. It corresponds to the compilers (GCC) version 16.0.1. The internals of the GNU compilers, including how to port them to new targets and some information about how to ...
๐ŸŒ
Linux Man Pages
man7.org โ€บ linux โ€บ man-pages โ€บ man1 โ€บ gcc.1.html
gcc(1) - Linux manual page
If the description for a particular option does not mention a source language, you can use that option with all supported languages. The usual way to run GCC is to run the executable called gcc, or machine-gcc when cross-compiling, or machine-gcc-version to run a specific version of GCC.
๐ŸŒ
GNU
gcc.gnu.org โ€บ onlinedocs
GCC online documentation - GNU Project
GCC 15.2 Standard C++ Library Reference Manual (also in PDF or XML GPL or XML GFDL or an HTML tarball)
๐ŸŒ
GitHub
github.com โ€บ gcc-mirror โ€บ gcc
GitHub - gcc-mirror/gcc
See the file gcc/doc/gcc.texi (together with other files that it includes) for usage and porting information. An online readable version of the manual is in the files gcc/doc/gcc.info*. See http://gcc.gnu.org/bugs/ for how to report bugs usefully.
Starred by 10.7K users
Forked by 4.7K users
Languages ย  C++ 30.1% | C 29.3% | Ada 14.0% | D 5.9% | Go 5.3% | HTML 3.6%
๐ŸŒ
GNU
gcc.gnu.org โ€บ onlinedocs โ€บ gccint
Top (GNU Compiler Collection (GCC) Internals)
This manual documents the internals of the GNU compilers, including how to port them to new targets and some information about how to write front ends for new languages. It corresponds to the compilers (GCC) version 16.0.1. The use of the GNU compilers is documented in a separate manual.
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ GNU_Compiler_Collection
GNU Compiler Collection - Wikipedia
3 weeks ago - The GNU Compiler Collection (GCC) (formerly GNU C Compiler) is a collection of compilers from the GNU Project that support various programming languages, hardware architectures, and operating systems.
๐ŸŒ
GNU
gcc.gnu.org โ€บ gcc-15
GCC 15 Release Series - GNU Project
GCC used to stand for the GNU C Compiler, but since the compiler supports several other languages aside from C, it now stands for the GNU Compiler Collection.
Find elsewhere
Top answer
1 of 10
411

First erase the current update-alternatives setup for gcc and g++:

sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++

Install Packages

It seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. However, we can explicitly install the following packages:

sudo apt-get install gcc-4.3 gcc-4.4 g++-4.3 g++-4.4

Install Alternatives

Symbolic links cc and c++ are installed by default. We will install symbol links for gcc and g++, then link cc and c++ to gcc and g++ respectively. (Note that the 10, 20 and 30 options are the priorities for each alternative, where a bigger number is a higher priority.)

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 20

sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc

sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++

Configure Alternatives

The last step is configuring the default commands for gcc, g++. It's easy to switch between 4.3 and 4.4 interactively:

sudo update-alternatives --config gcc
sudo update-alternatives --config g++

Or switch using script:

#!/bin/sh

if [ -z "$1" ]; then
    echo "usage: $0 version" 1>&2
    exit 1
fi

if [ ! -f "/usr/bin/gcc-$1" ] || [ ! -f "/usr/bin/g++-$1" ]; then
    echo "no such version gcc/g++ installed" 1>&2
    exit 1
fi

update-alternatives --set gcc "/usr/bin/gcc-$1"
update-alternatives --set g++ "/usr/bin/g++-$1"
2 of 10
62

execute in terminal :

gcc -v
g++ -v

Okay, so that part is fairly simple. The tricky part is that when you issue the command GCC it is actually a sybolic link to which ever version of GCC you are using. What this means is we can create a symbolic link from GCC to whichever version of GCC we want.

  • You can see the symbolic link :
ls -la /usr/bin | grep gcc-4.4
ls -la /usr/bin | grep g++-4.4
  • So what we need to do is remove the GCC symlink and the G++ symlink and then recreate them linked to GCC 4.3 and G++ 4.3:
rm /usr/bin/gcc
rm /usr/bin/g++

ln -s /usr/bin/gcc-4.3 /usr/bin/gcc
ln -s /usr/bin/g++-4.3 /usr/bin/g++
  • Now if we check the symbolic links again we will see GCC & G++ are now linked to GCC 4.3 and G++ 4.3:
ls -la /usr/bin/ | grep gcc
ls -la /usr/bin/ | grep g++
  • Finally we can check our GCC -v again and make sure we are using the correct version:
gcc -v
g++ -v
๐ŸŒ
GNU
gcc.gnu.org โ€บ install โ€บ download.html
Downloading GCC - GNU Project
Please refer to the releases web page for information on how to obtain GCC.
๐ŸŒ
GNU
gcc.gnu.org โ€บ install
Installing GCC - GNU Project
This document describes the generic installation procedure for GCC as well as detailing some target specific installation instructions.
Top answer
1 of 7
74

That's kind of right, but incomplete. -g requests that the compiler and linker generate and retain source-level debugging/symbol information in the executable itself.

If...

  • the program happens to later crash and produce a core file (which suggests some problem in the actual code), or
  • a deliberate OS command forced it to core (e.g. kill -SIGQUIT pid), or
  • the program calls a function that dumps core (e.g. abort)

...- none of which are actually caused by the use of -g - then the debugger will know how to read that "-g" symbol information from the executable and cross-reference it with the core. This means you can see the proper names of variables and functions in your stack frames, get line numbers and see the source as you step around in the executable.

That debug information is useful whenever debugging - whether you started with a core or just the executable alone. It even helps produce better output from commands like pstack.

Note that your environment may have other settings to control whether cores are generated (they can be big, and there's no general way to know if/when they can be removed, so they're not always wanted). For example, on UNIX/LINUX shells it's often ulimit -c.

You may also be interested to read about DWARF Wikipedia - a commonly used debugging information format for encoding the embedded debug/symbol information in executable/library objects (e.g. on UNIX and Linux).

UPDATE per Victor's request in comments...

Symbol information lists identifiers from the source code (usually only after any name mangling needed), the (virtual) memory addresses/offsets at which they'll be loaded in the process memory, the type (e.g. data vs. code). For example...

$ cat ok.cc
int g_my_num;
namespace NS { int ns_my_num = 2; }
int f() { return g_my_num + NS::ns_my_num; }
int main() { return f(); }

$ g++ -g ok.cc -o ok    # compile ok executable with symbol info

$ nm ok    # show mangled identifiers
00000000004017c8 d _DYNAMIC
0000000000401960 d _GLOBAL_OFFSET_TABLE_
0000000000400478 R _IO_stdin_used
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
                 w _Jv_RegisterClasses
000000000040037c T _Z1fv                     # this is f()
0000000000401798 D _ZN2NS9ns_my_numE         # this is NS::ns_my_num
00000000004017a8 d __CTOR_END__
00000000004017a0 d __CTOR_LIST__
00000000004017b8 d __DTOR_END__
00000000004017b0 d __DTOR_LIST__
0000000000400540 r __FRAME_END__
00000000004017c0 d __JCR_END__
00000000004017c0 d __JCR_LIST__
00000000004017c8 d __TMC_END__
00000000004017c8 d __TMC_LIST__
0000000000401980 A __bss_start
0000000000401788 D __data_start
0000000000400440 t __do_global_ctors_aux
00000000004002e0 t __do_global_dtors_aux
0000000000401790 d __dso_handle
0000000000000000 a __fini_array_end
0000000000000000 a __fini_array_start
                 w __gmon_start__
0000000000000000 a __init_array_end
0000000000000000 a __init_array_start
00000000004003a0 T __libc_csu_fini
00000000004003b0 T __libc_csu_init
                 U __libc_start_main
0000000000000000 a __preinit_array_end
0000000000000000 a __preinit_array_start
0000000000401980 A _edata
0000000000401994 A _end
0000000000400494 T _fini
000000000040047c T _init
0000000000400220 T _start
000000000040024c t call_gmon_start
0000000000401980 b completed.6118
0000000000401788 W data_start
0000000000400270 t deregister_tm_clones
0000000000401988 b dtor_idx.6120
0000000000401994 A end
0000000000400350 t frame_dummy
0000000000401990 B g_my_num                   # our global g_my_num
0000000000400390 T main                       # the int main() function
00000000004002a0 t register_tm_clones

$ nm ok | c++filt            # c++filt "unmangles" identifiers...
00000000004017c8 d _DYNAMIC
0000000000401960 d _GLOBAL_OFFSET_TABLE_
0000000000400478 R _IO_stdin_used
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
                 w _Jv_RegisterClasses
000000000040037c T f()
0000000000401798 D NS::ns_my_num
00000000004017a8 d __CTOR_END__
00000000004017a0 d __CTOR_LIST__
00000000004017b8 d __DTOR_END__
00000000004017b0 d __DTOR_LIST__
0000000000400540 r __FRAME_END__
00000000004017c0 d __JCR_END__
00000000004017c0 d __JCR_LIST__
00000000004017c8 d __TMC_END__
00000000004017c8 d __TMC_LIST__
0000000000401980 A __bss_start
0000000000401788 D __data_start
0000000000400440 t __do_global_ctors_aux
00000000004002e0 t __do_global_dtors_aux
0000000000401790 d __dso_handle
0000000000000000 a __fini_array_end
0000000000000000 a __fini_array_start
                 w __gmon_start__
0000000000000000 a __init_array_end
0000000000000000 a __init_array_start
00000000004003a0 T __libc_csu_fini
00000000004003b0 T __libc_csu_init
                 U __libc_start_main
0000000000000000 a __preinit_array_end
0000000000000000 a __preinit_array_start
0000000000401980 A _edata
0000000000401994 A _end
0000000000400494 T _fini
000000000040047c T _init
0000000000400220 T _start
000000000040024c t call_gmon_start
0000000000401980 b completed.6118
0000000000401788 W data_start
0000000000400270 t deregister_tm_clones
0000000000401988 b dtor_idx.6120
0000000000401994 A end
0000000000400350 t frame_dummy
0000000000401990 B g_my_num
0000000000400390 T main
00000000004002a0 t register_tm_clones

Notes:

  • our functions f() and main() are type T (which stands for "TEXT" - used for read-only non-zero memory content whether it's actually text or other data or executable code),
  • g_my_num is B being a global with implicitly zero-ed out memory, while
  • NS::ns_my_num is D as the executable has to explicitly provide the value 2 to occupy that memory.

The man/info-page for nm documents these things further....

2 of 7
13

The -g flag tells the compiler to generate debugging information. It has no impact on whether or not a core file will be generated. On most unix-like systems, that can be setup using the ulimit command.

๐ŸŒ
GNU
gcc.gnu.org โ€บ onlinedocs โ€บ gcc โ€บ Overall-Options.html
Overall Options (Using the GNU Compiler Collection (GCC))
Print (on the standard output) a description of the command-line options understood by gcc. If the -v option is also specified then --help is also passed on to the various processes invoked by gcc, so that they can display the command-line options they accept.
๐ŸŒ
Linux Man Pages
linux.die.net โ€บ man โ€บ 1 โ€บ gcc
gcc(1): GNU project C/C++ compiler - Linux man page
GCC is capable of preprocessing and compiling several files either into several assembler input files, or into one assembler input file; then each assembler input file produces an object file, and linking combines all the object files (those newly compiled, and those specified as input) into ...
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ GCC
GCC - Wikipedia
10 hours ago - Look up GCC in Wiktionary, the free dictionary. ... Global Certification Commission, an independent body of the World Health Organization for the eradication of wild polio ... Greater Chennai Corporation, civic body that governs the city of Chennai in India. Gateway Community Church, Baguio ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ linux-unix โ€บ gcc-command-in-linux-with-examples
gcc command in Linux with examples - GeeksforGeeks
October 4, 2025 - Example: This will compile the source.c file and give the output file as a.out file which is default name of output file given by gcc compiler, which can be executed using ./a.out
Top answer
1 of 11
979

gcc and g++ are compiler-drivers of the GNU Compiler Collection (which was once upon a time just the GNU C Compiler).

Even though they automatically determine which backends (cc1 cc1plus ...) to call depending on the file-type, unless overridden with -x language, they have some differences.

The probably most important difference in their defaults is which libraries they link against automatically.

According to GCC's online documentation link options and how g++ is invoked, g++ is roughly equivalent to gcc -xc++ -lstdc++ -shared-libgcc (the 1st is a compiler option, the 2nd two are linker options). This can be checked by running both with the -v option (it displays the backend toolchain commands being run).

By default (and unlike gcc), g++ also adds linker option -lm -- to link against libm which contains implementations for math.h.

2 of 11
592

GCC: GNU Compiler Collection

  • Referrers to all the different languages that are supported by the GNU compiler.

gcc: GNU C      Compiler
g++: GNU C++ Compiler

The main differences:

  1. gcc will compile: *.c\*.cpp files as C and C++ respectively.
  2. g++ will compile: *.c\*.cpp files but they will all be treated as C++ files.
  3. Also if you use g++ to link the object files it automatically links in the std C++ libraries (gcc does not do this).
  4. gcc compiling C files has fewer predefined macros.
  5. gcc compiling *.cpp and g++ compiling *.c\*.cpp files has a few extra macros.

Extra Macros when compiling *.cpp files:

#define __GXX_WEAK__ 1
#define __cplusplus 1
#define __DEPRECATED 1
#define __GNUG__ 4
#define __EXCEPTIONS 1
#define __private_extern__ extern
๐ŸŒ
SourceForge
sourceforge.net โ€บ projects โ€บ gcc-win64
gcc-win64 download | SourceForge.net
Download gcc-win64 for free. x64 build of GCC for Windows. x64 C/C++ compiler for Windows using (unofficial build): - gmp - mpfr - mpc - isl - cloog - mingw-w64 - gcc - seh You need at least core2 command set support to run this application. Note that every version with bundled gdb needs at ...
๐ŸŒ
OSDev Wiki
wiki.osdev.org โ€บ GCC_Cross-Compiler
GCC Cross-Compiler - OSDev Wiki
This tutorial focuses on creating a GCC cross-compiler for your own operating system.