"g++" and "c++" compiler

41,574

Solution 1

This is typical Ubuntu symlink mayhem.

If you ls -l /usr/bin/c++, you will see it is actually a symbolic link. to:

/etc/alternatives/c++

Which in turn, is also a symbolic link to:

/usr/bin/g++

So, on Ubuntu systems, c++ is g++. The reasoning behind the link indirection is that there are multiple packages that could provide a c++ compiler (such as different versions of g++). You'll see this a lot on Ubuntu. For example, qmake is a link to a file in /etc/alternatives, which is (on my system) a link back to /usr/bin/qmake-qt3.

Solution 2

c++ is a standard name of a C++ compiler on a system.

On a GNU system you almost surely have GCC (GNU compiler collection) installed, which includes a C++ compiler named g++ ('g' for GNU). But to be POSIX-compatible, they install this compiler as c++ also, sometimes c++ is a symbolic link to g++ sometimes it's a hard link, sometimes it's just the same file installed twice.

This can be not the case for other systems like FreeBSD or NetBSD. It's possible that those systems don't have GCC (and other GNU stuff) installed.

On my system these two files are just identical:

% diff `which c++` `which g++`
% echo $?
0

This means that c++ at least invokes the same compiler, but theoretically it can interpret some command line options differently or have some different defaults. Someone with more knowledge is free to extend the answer in this regard.

Solution 3

On my machine, c++ is a link:

$ readlink /usr/bin/c++
/etc/alternatives/c++
$ readlink /etc/alternatives/c++
/usr/bin/g++

So c++ is just a link to g++.

Solution 4

g++ is the gnu c++ compiler where c++ is the system c++ compiler, in the case of ubuntu C++ is a link to g++ however in another system it could very well be a link to a non gcc compiler. as someone else said vi vs vim. just because a link to vi exists on the system doesn't mean that it's vim could be any vi clone.

Share:
41,574
Tim
Author by

Tim

Elitists are oppressive, anti-intellectual, ultra-conservative, and cancerous to the society, environment, and humanity. Please help make Stack Exchange a better place. Expose elite supremacy, elitist brutality, and moderation injustice to https://stackoverflow.com/contact (complicit community managers), in comments, to meta, outside Stack Exchange, and by legal actions. Push back and don't let them normalize their behaviors. Changes always happen from the bottom up. Thank you very much! Just a curious self learner. Almost always upvote replies. Thanks for enlightenment! Meanwhile, Corruption and abuses have been rampantly coming from elitists. Supportive comments have been removed and attacks are kept to control the direction of discourse. Outright vicious comments have been removed only to conceal atrocities. Systematic discrimination has been made into policies. Countless users have been harassed, persecuted, and suffocated. Q&A sites are for everyone to learn and grow, not for elitists to indulge abusive oppression, and cover up for each other. https://softwareengineering.stackexchange.com/posts/419086/revisions https://math.meta.stackexchange.com/q/32539/ (https://i.stack.imgur.com/4knYh.png) and https://math.meta.stackexchange.com/q/32548/ (https://i.stack.imgur.com/9gaZ2.png) https://meta.stackexchange.com/posts/353417/timeline (The moderators defended continuous harassment comments showing no reading and understanding of my post) https://cs.stackexchange.com/posts/125651/timeline (a PLT academic had trouble with the books I am reading and disparaged my self learning posts, and a moderator with long abusive history added more insults.) https://stackoverflow.com/posts/61679659/revisions (homework libels) Much more that have happened.

Updated on July 08, 2022

Comments

  • Tim
    Tim almost 2 years

    I just found on my Ubuntu, there are two different C++ compilers: /usr/bin/g++ and /usr/bin/c++. I am not familiar with the latter, but man c++ just jumps to the manpage of gcc. I wonder what is their difference as C++ compilers?

  • Laser
    Laser almost 12 years
    thanks i check md5sum of c++ and g++ and they are same! But what for here 2 files that make same job?
  • ams
    ams almost 12 years
    Yep, there is no difference, and you can use whichever you like. If you use GCC specific options in your build then I would recommend g++, just so it's clear, but you should always let the user override the compiler with the CXX variable.
  • Claudio
    Claudio almost 12 years
    Even if the files are identical it doesn't mean they are equivalent. A program may behave differently depending on what name was used to call it (for example gunzip and zcat are link to gzip, and different default arguments are used when gzip is called with the other two names).
  • unkulunkulu
    unkulunkulu almost 12 years
    @Claudio, oops, right, forgot about that. Then this can be not only imprecise answer, but wrong altogether.
  • unkulunkulu
    unkulunkulu almost 12 years
    @Claudio, And on BSD systems it's almost surely wrong. I'm confused now, I have to revise the answer.
  • unkulunkulu
    unkulunkulu almost 12 years
    @Claudio, changed the answer to be correct at least, but still don't know the real difference, do you?
  • Claudio
    Claudio almost 12 years
    @unkulunkulu No idea if there is any difference.
  • Konrad Borowski
    Konrad Borowski over 10 years
    FreeBSD 9 has gcc installed, but it will be removed for most platforms in FreeBSD 10.
  • Trevor Boyd Smith
    Trevor Boyd Smith over 8 years
    on Fedora 21, /usr/bin/c++ and /usr/bin/g++ are both binary files (i.e. not symlinks)... but the two files are identical (same number of bytes and same md5sum). (A symlink seems more appropriate... not sure why they did a copy of the same file. Both g++ and c++ are provided by the same rpm gcc-c++.)