What exactly is g++?

1

There's one thing that I don't understand - and that is the question what is g++?

I've searched for the wide web (in every way I've thought of, at least). No result yielded (the closest that I've came to what g++ is, is this).

So is g++ a library designed for the GCC Compiler (or is it a compiler itself)? I know that by typing

$sudo apt-get install g++

in Debian-based systems will install g++. But right now I'm pretty confused at what g++ is. So is it a C++ Library or a compiler itself? As far as I know, searching g++ on Google (I bet other search engines, too), returns no helpful results.

Thank you for answering.

John Lee

Posted 2018-06-14T13:17:13.490

Reputation: 13

5

I just googled "g++" and this was the first question. The answers are pretty good.

– gronostaj – 2018-06-14T13:21:45.060

@gronostaj thank you! I've taken a read on that. – John Lee – 2018-06-14T14:12:51.970

"returns no helpful results." I beg to differ. How are you performing that search? – None – 2018-06-14T14:46:51.300

Answers

2

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++

plugwash

Posted 2018-06-14T13:17:13.490

Reputation: 4 587