简体   繁体   中英

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. Along the way, I unintentionally used different compilers, namely gcc and 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. Obviously when you enter a compiler's command without arguments, you get an error saying that there are no input files. I thought gcc was supposed to say something like this when I just typed the command:

gcc: error: no input files

But it's the same when I tried it for clang. It said clang: error: no input files for both commands. So my question is, am I running clang when using gcc? If so, how do I fix that?

gcc and clang are two rather different compilers. But due to gcc's popularity, clang deliberately copies many of its features. And in some environments (such as recent Macs), clang is installed with an alias so that if you type gcc , you get 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. If you need to use gcc you can install with homebrew like

brew install gcc 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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