我知道在大多数 GNU/Linux 系统上,可以通过命令行中的名称“cc”(而不是“gcc”)来调用 GCC。 当以一种方式调用 GCC 时,GCC 的行为与另一种方式有什么不同吗?
例如,我知道通过名称“g++”而不是“gcc”调用 GCC 会导致 GCC 的行为不同(它将 .c 文件视为 C++ 源代码和 C++ 标准库中的链接)。 “gcc”与“cc”之间的行为是否有类似的差异?
编辑:到目前为止收到的答案都没有给出“是”或“否”的“肯定”或“否”来说明如果以一种方式调用 GCC 与另一种方式调用时 GCC 的行为是否会有所不同。 然而,深入研究源代码以检查其行为的想法引导我走上了这条道路。 根据我在那里的发现,我现在相信答案是:
不。 无论是通过“gcc”还是“cc”调用,GCC 的行为都是相同的。
I am aware that on most GNU/Linux systems, GCC can be invoked by the name "cc" from the command line (as opposed to "gcc"). Is there any difference in GCC's behavior when it is invoked one way versus the other?
For example, I know that invoking GCC through the name "g++" instead of "gcc" causes GCC to behave differently (it treats .c files as C++ source and links-in the C++ standard library). Is there any similar difference in behavior between "gcc" versus "cc"?
EDIT: None of the answers received so far gave a definitive "yes" or "no" as to whether GCC will behave differently if invoked one way versus the other. However, the idea given to dive into the source to check its behavior lead me down that path. Based upon what I found there, I now believe that the answer is:
No. GCC behaves the same regardless of whether it is called via "gcc" or "cc".
发布评论
评论(11)
为了笑,我只是追踪了 gcc 中如何使用
argv[0]
(main.c
->top_lev.c
->opts.c
-> ;langhooks.c
),并且argv[0]
当前的用途只不过是在失败时为malloc
提供一些报告。 如果argv[0]
是gcc
以外的任何内容,则似乎不会发生任何行为变化。For grins, I just traced down how
argv[0]
is used from within gcc (main.c
->top_lev.c
->opts.c
->langhooks.c
) and it appears thatargv[0]
is currently used for nothing more than givingmalloc
something to report when it fails. There doesn't appear to be any behavior change ifargv[0]
is anything other thangcc
.在我看来
cc
(链接到一些旧的 SUS 规范)旨在成为系统编译器的供应商中立接口。 它被标记为遗留:POSIX 有一个名为
c99
的实用程序,我使用它相信是c89
的后继者。 它说我不太熟悉所有这些不同的标准,但它看起来像更新的 SUSv3 ( POSIX:2004) 和最近的 POSIX:2008 (似乎还没有 SUS 编号)不再指定名为
cc
的实用程序,而仅指定名为c99
的实用程序。 顺便说一句,我的 Linux 系统 (Arch_Linux) 包含c99
的联机帮助页,但是不是c89
,但仅包含一个名为cc
的实用程序,但既不是c89
也不是c99
。 那里有很多混乱:)It looks to me that
cc
(link to some old SUS specification) is intended to be the vendor-neutral interface to the system's compiler. It's marked as legacy:POSIX has a utility called
c99
which I believe is the successor ofc89
. It saysI'm not really familiar to all those different standards, but it looks like the more recent SUSv3 (POSIX:2004) and the yet more recent POSIX:2008 (doesn't seem to have a SUS number yet) do not specify a utility called
cc
anymore, but only the utility calledc99
. Incidentally, my Linux system (Arch_Linux) contains a manpage ofc99
but notc89
, but only contains a utility calledcc
, but neitherc89
norc99
. Much confusion in there :)在我的 mac 上使用
man gcc
:基于此,我假设 cc 和 gcc 的行为方式相同。
On my mac from
man gcc
:Based on that I would assume that cc and gcc behave the same way.
我今天也有同样的疑问,我尝试自己找到它:
which
- 确定可执行位置file
- 确定文件类型所以,基本上
cc
指向gcc
。您还可以使用 cc -v 和 gcc -v 进行检查。 如果它们打印出相同的内容,则意味着它们完全相同。
I had the same doubt today and I tried to find it on my own:
which
- Determine executable locationfile
- Determine file typeSo, basically
cc
points togcc
.You could also check using
cc -v
andgcc -v
. If they print out the same thing, that means they are exactly the same.即使 gcc 的操作与 argv[0] 的值无关,但并非所有软件都会以相同的方式操作,无论您指定哪个编译器。
在 RHEL 5.5 (gcc 4.1.2) 上构建 zlib 1.2.5 时:
但是:
并且:
配置脚本没有考虑 Linux 系统上的 cc 可能是 gcc 的可能性。 所以,要小心你的假设有多深。
Even if gcc operates the same independent of argv[0]'s value, not all software will operate the same regardless of which you specify as the compiler.
When building zlib 1.2.5 on RHEL 5.5 (gcc 4.1.2):
But:
And:
The configure script does not consider the possibility that cc on a Linux system could be gcc. So, be careful how far you take your assumptions.
cc 只是调用编译器的 UNIX 方式,它适用于所有 Unices。
cc is just the UNIX way of calling the compiler, it will work on all Unices.
该线程可能很旧,但我想添加一些内容
(也许将来有人会发现它)。
如果你
用“gcc”编译这个程序,并传递“AAAAAAAAAAAAAAAAAAAAAAAAA”作为参数,它不会溢出到 buffer2,而如果你用“cc”编译,它会溢出,这对我来说是一个提示,如果你使用“gcc” ”,内存管理的工作方式有所不同,可能是通过在字段 buff1 和 buff1 的内存段之间放置空间来实现的。 增益2?
也许有更多经验的人可以为这里的黑暗带来光明。
this thread might be old but I want to add something to it
(maybe someone will find it in the future).
If you compiled this program
with "gcc", and you pass it "AAAAAAAAAAAAAAAAAAAAAAAAA" as argument, it will not overflow into buffer2, while it DOES if you compiled with "cc", which for me is a hint that if you used "gcc", the memory management works different, maybe by putting space between the memory segments of the fields buff1 & buff2 ?
Maybe someone with more experiance can put light into the darkness here.
GCC 文档中没有任何内容表明,如果 GCC 的可执行文件名称不是 gcc 而是 cc,那么 GCC 的行为会有任何不同。 GNU Fortran 编译器甚至提到:
Nothing in the GCC documentation indicates that GCC would behave any differently if its executable name is not gcc but cc. The GNU Fortran compiler even mentions that:
根据我在 Ubuntu 14.04 中的经验,情况并非如此。
当我使用以下命令编译程序时:
我的代码行为没有发生任何变化。但是当我使用
它进行编译时,它的行为确实有所不同(在这两种情况下,我都将适当的更改合并到描述的代码中此处 使 -finstrument-functions 工作)。
Based on my experienced in Ubuntu 14.04, this hasn't been the case.
When I compile my program using:
I don't get any change in the behavior of my code. But when I compile using
It does behave differently. (In both cases, I incorporated the appropriate changes into my code described here to make -finstrument-functions work).
考虑到它来自 UNIX,我会说“cc”是通用名称,“gcc”是实际的编译器。 即“gcc”提供“cc”,因此寻找“cc”的程序将找到并使用“cc”,而完全不知道正在使用的实际编译器。
另外,UNIX 程序应该不知道用于调用它们的实际名称(想想 Windows 桌面快捷方式 - 检查快捷方式的名称是没有意义的),所以,不,“gcc”和“cc”会执行以下操作:如果“cc”是“gcc”的链接,则同样的情况。
当然,除非“cc”不是符号链接,而是调用 gcc 的 shell 脚本。
Considering this is coming from UNIX, I'd say that "cc" is the generic name and "gcc" is the actual compiler. i.e. "gcc" provides "cc" so a program looking for "cc" would find and use "cc", blissfully ignorant of the actual compiler being used.
Also, UNIX programs should be ignorant of the actual name used to call them (think Windows Desktop shortcuts -- it doesn't make sense to check what the shortcut was called), so, no, "gcc" and "cc" do the same thing if "cc" is a link to "gcc".
Unless, of course, "cc" is not a symlink but a shellscript calling gcc.
对于我的操作系统 (Ubuntu 14.04),
cc
不允许制表符完成,而gcc
允许。For my OS (Ubuntu 14.04)
cc
doesn't allow tab completion, whereasgcc
does.