🌐
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
Our releases are available on the GNU download server and its mirrors.
GCC Releases
GCC releases may be downloaded from our mirror sites. Important: these are source releases, so will be of little use if you do not already have a C++ compiler installed. As one option, there are pre-compiled binaries.
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)
🌐
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. The Free Software Foundation (FSF) distributes GCC as free software under the GNU General ...
🌐
Reddit
reddit.com β€Ί r/cpp_questions β€Ί what exactly is g++?
r/cpp_questions on Reddit: What Exactly is G++?
June 17, 2022 -

I am pretty sure it is a standalone compiler that can make exe’s and stuff. However, I just don’t get what is so special about it, and why it seems like almost everyone uses it. I use visual studio, and I enjoy doing game development with unreal, and making algorithm visualizers and stuff with simple libraries like sfml, and since it’s an ide I just assumed I just never have to touch G++.

Edit: also it’s probably good to mention I am going into my 5th semester of my cs bachelors. So idk if thats good or not to not really of known exactly what it was, but thanks to everyone for all the feedback.

🌐
Northern Illinois University
faculty.cs.niu.edu β€Ί ~hutchins β€Ί csci241 β€Ί compiler.htm
The GNU G++ Compiler
The name of the compiler is ... g++ for the C or C++ compiler respectively. Because of the similarities between C and C++, the two commands actually call the same compiler with different default options.
🌐
GNU
gcc.gnu.org β€Ί onlinedocs β€Ί gcc-3.3.6 β€Ί gcc β€Ί G_002b_002b-and-GCC.html
G++ and GCC - Using the GNU Compiler Collection (GCC)
Several versions of the compiler (C, C++, Objective-C, Ada, Fortran, Java and treelang) are integrated; this is why we use the name β€œGNU Compiler Collection”. GCC can compile programs written in any of these languages.
Top answer
1 of 1
5

The only differences between gcc and g++ are that:

  • when the driver is used to invoke the linker, g++ causes libstdc++ to be linked as part of "stdlibs", while gcc will link only libc.
  • g++ will compile .c, .h and .i files as C++ unless the -x option is specified.

Both drivers will compile C or C++ depending on either the filename extension, or command-line switches. If you invoke the compiler-driver for compilation only and invoke the linker (ld) directly, using gcc or g++ -x, it makes no difference which you use.

Equally, if you invoke the gcc driver for C++ code and explicitly link stdlibc++ it also makes no difference - so long as your crt0.o is not C-only - a C++ runtime start-up must invoke global static constructors before main()) - this is likely to already be the case.

The definitive word from the documentation:

3.3 Compiling C++ Programs

C++ source files conventionally use one of the suffixes β€˜.C’, β€˜.cc’, β€˜.cpp’, β€˜.CPP’, β€˜.c++’, β€˜.cp’, or β€˜.cxx’; C++ header files often use β€˜.hh’, β€˜.hpp’, β€˜.H’, or (for shared template code) β€˜.tcc’; and preprocessed C++ files use the suffix β€˜.ii’. GCC recognizes files with these names and compiles them as C++ programs even if you call the compiler the same way as for compiling C programs (usually with the name gcc).

However, the use of gcc does not add the C++ library. g++ is a program that calls GCC and automatically specifies linking against the C++ library. It treats β€˜.c’, β€˜.h’ and β€˜.i’ files as C++ source files instead of C source files unless -x is used. This program is also useful when precompiling a C header file with a β€˜.h’ extension for use in C++ compilations. On many systems, g++ is also installed with the name c++.

When you compile C++ programs, you may specify many of the same command-line options that you use for compiling programs in any language; or command-line options meaningful for C and related languages; or options that are meaningful only for C++ programs. See Options Controlling C Dialect, for explanations of options for languages related to C. See Options Controlling C++ Dialect, for explanations of options that are meaningful only for C++ programs.

If you want to use just one, I suggest you use gcc and separately invoke the linker or explicitly link -libstdc++. That way the compilation mode will be dependent on the filename extension. Using g++ -x to compile C code is just going to cause confusion.

Find elsewhere
Top answer
1 of 1
1

the GCC Compiler

One source of confusion here is that GCC has multiple meanings, sometimes it can refer to the C compiler specifically ("GNU C Compiler"), sometimes it can refer to the whole collection of compilers ("GNU Compiler Collection").


The GNU compiler collection is as the name suggests a collection of compilers that share some code, among the collection are a C compiler and a C++ compiler.

The "gcc" and "g++" binaries are "compiler drivers", they handle parsing the command lines and calling the programs (compiler, linker, preprocessor if it is not integrated) that do the actual work with the correct options.

The actual compilers are "cc1" for C and "cc1plus" for C++.

"g++" has additional behaviours in it specific to c++, such that it can compile and link a c++ program out of the box. See https://stackoverflow.com/a/173007/5083516 for more details.


Now for the Debian packages.

Debian names it's "gcc" and "g++" binaries with an architecture prefix and a version suffix, so for example on the Debian system i'm using to write this post "g++" is a symlink to "g++-6" which in-turn is a symlink to x86_64-linux-gnu-g++-6

The Debian "g++" package doesn't actually contain the compiler, it merely contains the symlinks from un-versioned names to versioned names and (in Debian stretch) depends on "cpp", "g++-6", "gcc" and "gcc-6" (Other releases will have a different version number).

The Debian "g++-6" package contains the actual binaries for g++ version 6.x (named as x86_64-linux-gnu-g++-6 on x86-64) and cc1plus (located in a directory that is specific to compiler version and target architecture).

"g++-6" in turn depends on "libstdc++-6-dev", this contains the headers for the c++ standard library, the static version of the C++ standard library and a symlink to the dynamic version of the C++ standard library (and a couple of other static libraries that only matter in unusual circumstances)

"libstdc++-6-dev" in turn depends on "libstdc++6" which contains the dynamic version of the C++ standard library (note that the 6 in libstdc++-6-dev and the 6 in libstdc++6 refer to different things, in the former case it's the version of the compiler, in the latter case it's the soversion of the standard C library).

So installing the "g++" package pulls in everything you need to write programs in C++

🌐
Free Software Directory
directory.fsf.org β€Ί wiki β€Ί G++
G++ - Free Software Directory
g++ is the traditional nickname of GNU C++, a freely redistributable C++ compiler.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί linux-unix β€Ί compiling-with-g-plus-plus
Compiling with g++ - GeeksforGeeks
April 8, 2024 - g++ command is a GNU c++ compiler invocation command, which is used for preprocessing, compilation, assembly and linking of source code to generate an executable file.
🌐
USC CS and ECE
bytes.usc.edu β€Ί cs104 β€Ί wiki β€Ί gcc
Usc
GCC, the GNU Compiler Collection, is used to build your C++ executables. If you’re interested in reading about GCC, you can check out the GNU website. You can also take ITP 439, which covers compiler development.
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
🌐
Quora
quora.com β€Ί Is-g++-the-best-c++-compiler-Which-would-be-the-best-one
Is g++ the best c++ compiler? Which would be the best one? - Quora
Answer (1 of 3): It really depends on what you mean by "best". Do you mean most standard compliant? Do you mean "has the richest set of extensions"? Do you mean "has best code quality", or "most hackable source", or "has the most user-friendly error messages". Even the obvious answer to "has the...
🌐
Compiler Explorer
godbolt.org
Compiler Explorer
Clone CompilerExecutor From ThisOpt RemarksStack UsagePreprocessorASTLLVM IRClangIROpt PipelineDeviceRust MIRRust HIRRust Macro ExpansionGHC CoreGHC STGGHC CmmClojure Macro ExpansionYul (Solidity IR)GCC Tree/RTLGNAT Debug TreeGNAT Debug Expanded CodeControl Flow GraphClaude Explain
🌐
Incredibuild
incredibuild.com β€Ί home β€Ί integrations β€Ί gcc
What is GNU Compiler Collection (GCC) | Incredibuild
September 17, 2024 - The GNU Compiler Collection, commonly known as GCC, is a set of compilers and development tools available for Linux, Windows, various BSDs, and a wide assortment of other operating systems.
🌐
Ohio Supercomputer Center
osc.edu β€Ί resources β€Ί available_software β€Ί software_list β€Ί gnu_compilers
GNU Compilers | Ohio Supercomputer Center
July 29, 2025 - Fortran, C and C++ compilers produced by the GNU Project. Availability and Restrictions Versions The GNU Compiler Collection (GCC) are available on all our clusters. These are the versions currently available: Version Pitzer Ascend Cardinal Notes 11.4.1 X# X# X# 12.3.0 X X X* 13.2.0 X X X * ...
🌐
GitHub
github.com β€Ί gcc-mirror β€Ί gcc
GitHub - gcc-mirror/gcc
This directory contains the GNU Compiler Collection (GCC). The GNU Compiler Collection is free software. See the files whose names start with COPYING for copying permission. The manuals, and some of the runtime libraries, are under different terms; see the individual source files for details.
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%
🌐
GitHub
github.com β€Ί wyk9787 β€Ί G-Compiler
GitHub - wyk9787/G-Compiler: A compiler written in C/C++ that is able to compile an OCaml-syntax-like toy programming language.
G-Compiler is a compiler written in C/C++ that is able to compile a OCaml-syntax-like functional programming language with state, named G. You can find grammar for G here.
Author Β  wyk9787