首页 > mac 使用gcc 为什么编译错误是clang 提示?

mac 使用gcc 为什么编译错误是clang 提示?

在mac下使用如下gcc命令编译:

gcc  relearn.c  support.c -o -g relearn
clang: error: no such file or directory: 'relearn'

gcc是在安装xcode时自动安装的
clang是编译器前端,为什么调用gcc是使用clang,还是mac下使用gcc命令被连接到clang完成,如果是这样,clang只是前端,从中间代码到机器指令,又是那个程序完成的呢?


作为@Windoze 答案的补充,你可以先在shell中用gcc -v查看gcc的版本信息,OS X最新版的应该是这样:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix

而直接查看clang -v,就是这一个样子的:

Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix

同时我的Mac上还通过Homebrew安装了GCC-4.8,用gcc-4.8 -v查看,可见:

Using built-in specs.
COLLECT_GCC=gcc-4.8
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/4.8.2/libexec/gcc/x86_64-apple-darwin13.1.0/4.8.2/lto-wrapper
Target: x86_64-apple-darwin13.1.0
Configured with: ../configure --build=x86_64-apple-darwin13.1.0 --prefix=/usr/local/Cellar/gcc/4.8.2 --enable-languages=c,c++,objc,obj-c++ --program-suffix=-4.8 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-cloog=/usr/local/opt/cloog --with-isl=/usr/local/opt/isl --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --enable-plugin --disable-nls --enable-multilib
Thread model: posix
gcc version 4.8.2 (GCC)

所以就是:OS X里本身没有gcc,而XCode 5的Command Line Tools中提供的是苹果做的clang。最终就是这个样子啦。


因为从Mac OS X 10.9/Xcode 5开始,系统里没有GCC了,你以为是GCC的那些gccg++之类的命令只是clang的别名。

【热门文章】
【热门文章】