“g++”和“c++”编译器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1712756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"g++" and "c++" compiler
提问by Tim
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?
我刚刚在我的 Ubuntu 上发现,有两种不同的 C++ 编译器:/usr/bin/g++ 和 /usr/bin/c++。我对后者不熟悉,但是 man c++ 只是跳转到 gcc 的联机帮助页。我想知道它们与 C++ 编译器有什么区别?
回答by MichaelM
This is typical Ubuntu symlink mayhem.
这是典型的 Ubuntu 符号链接混乱。
If you ls -l /usr/bin/c++
, you will see it is actually a symbolic link. to:
如果你ls -l /usr/bin/c++
,你会看到它实际上是一个符号链接。到:
/etc/alternatives/c++
Which in turn, is also a symbolic link to:
反过来,这也是指向以下内容的符号链接:
/usr/bin/g++
So, on Ubuntu systems, c++ isg++. 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.
因此,在 Ubuntu 系统上,c++是g++。链接间接背后的原因是有多个包可以提供 c++ 编译器(例如不同版本的 g++)。你会在 Ubuntu 上看到很多。例如,qmake 是指向 /etc/alternatives 中文件的链接,它(在我的系统上)是指向 /usr/bin/qmake-qt3 的链接。
回答by unkulunkulu
c++
is a standard name of a C++
compiler on a system.
c++
是C++
系统上编译器的标准名称。
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.
在 GNU 系统上,您几乎肯定已经GCC
安装了(GNU 编译器集合),其中包括一个C++
名为g++
(GNU 的“g”)的编译器。但是为了与 POSIX 兼容,他们也安装了这个编译器c++
,有时c++
是符号链接,g++
有时是硬链接,有时只是安装了两次的同一个文件。
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.
对于 FreeBSD 或 NetBSD 等其他系统,情况可能并非如此。这些系统可能没有安装 GCC(和其他 GNU 东西)。
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.
这意味着c++
至少调用相同的编译器,但理论上它可以不同地解释一些命令行选项或具有一些不同的默认值。有更多知识的人可以自由扩展这方面的答案。
回答by Sophie Alpert
On my machine, c++
is a link:
在我的机器上,c++
是一个链接:
$ readlink /usr/bin/c++
/etc/alternatives/c++
$ readlink /etc/alternatives/c++
/usr/bin/g++
So c++
is just a link to g++
.
所以c++
只是一个链接g++
。
回答by xenoterracide
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.
g++ 是 gnu c++ 编译器,其中 c++ 是系统 c++ 编译器,在 ubuntu 的情况下,C++ 是指向 g++ 的链接,但是在另一个系统中,它很可能是指向非 gcc 编译器的链接。正如其他人所说的vi vs vim。仅仅因为系统上存在指向 vi 的链接并不意味着它的 vim 可以是任何 vi 克隆。