“g++” and “c++” compiler

孤者浪人 提交于 2019-12-18 12:43:30

问题


I just found on my Ubuntu, there are two different C++ compiler: /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?


回答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.




回答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.




回答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++.




回答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.



来源:https://stackoverflow.com/questions/1712756/g-and-c-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!