简体   繁体   English

clang 是否应该与 gcc 相同,反之亦然?

[英]Is clang supposed to be the same as gcc and vice versa?

I was trying to edit some C code, compile it, and test it.我试图编辑一些 C 代码,编译并测试它。 Along the way, I unintentionally used different compilers, namely gcc and clang.一路上,我无意中使用了不同的编译器,即 gcc 和 clang。 Then I got bored and just typed both of the compiler's commands in the command line (weird but ok).然后我很无聊,只是在命令行中输入了编译器的两个命令(奇怪但没问题)。 I noticed that when I did that, gcc was clang and clang was just clang.我注意到,当我这样做时,gcc 是 clang 和 clang 只是 Z2C5517DB7BC397F9B14AE357A7CEFF4 Obviously when you enter a compiler's command without arguments, you get an error saying that there are no input files.显然,当您输入没有 arguments 的编译器命令时,您会收到一条错误消息,指出没有输入文件。 I thought gcc was supposed to say something like this when I just typed the command:当我刚刚输入命令时,我以为 gcc 应该说这样的话:

gcc: error: no input files

But it's the same when I tried it for clang.但是当我为 clang 尝试它时,它是一样的。 It said clang: error: no input files for both commands.它说clang: error: no input files So my question is, am I running clang when using gcc?所以我的问题是,我在使用 gcc 时是否在运行 clang? If so, how do I fix that?如果是这样,我该如何解决?

gcc and clang are two rather different compilers. gcc 和 clang 是两个完全不同的编译器。 But due to gcc's popularity, clang deliberately copies many of its features.但是由于 gcc 的流行,clang 故意复制了它的许多特性。 And in some environments (such as recent Macs), clang is installed with an alias so that if you type gcc , you get clang .在某些环境中(例如最近的 Mac), clang 使用别名安装,因此如果您键入gcc ,您会得到clang Sounds like that's what might be happening for you.听起来这就是你可能发生的事情。

Apple used to use gcc in Xcode a long time ago, and then they made clang and running gcc would invoke clang to allow old build script to work correctly. Apple used to use gcc in Xcode a long time ago, and then they made clang and running gcc would invoke clang to allow old build script to work correctly. If you need to use gcc you can install with homebrew like如果您需要使用 gcc 您可以使用自制软件安装

brew install gcc 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM