Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 910
Tim Avatar asked Nov 11 '09 03:11

Tim


People also ask

Is G ++ a C compiler?

g++ will compile . c, . h and . i files as C++ unless the -x option is specified.

What is GCC and g ++ compiler?

g++ is used to compile C++ program. gcc is used to compile C program. g++ can compile any . c or . cpp files but they will be treated as C++ files only.

What is GCC and CC?

CC is the name given to the UNIX Compiler Command. It is used as the default compiler command for your operating system and also is executable with the same command. GCC, on the other hand, is the GNU Compiler operating system.

How does the GCC compiler work?

After the file is preprocessed, gcc moves it to the compiler. The compiler turns each line in the preprocessed file into assembly language, which are instructions in English mnemonics that have strong one-to-one correspondence to the machine code that computers can read.


2 Answers

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.

like image 98
MichaelM Avatar answered Oct 11 '22 06:10

MichaelM


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.

like image 27
unkulunkulu Avatar answered Oct 11 '22 05:10

unkulunkulu