gcc 版本显示 4.2.1 即使在安装 4.9 (Homebrew) 之后

gcc version showing 4.2.1 even after installing 4.9 (Homebrew)

我在 mac 中安装了带有自制软件的 gcc 4.9 版。但是当我在终端中检查 gcc 版本时,它仍然显示旧版本。

Aarons-MacBook-Air:bin Aaron$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix

请帮忙

homebrew 安装带有版本特定后缀的 gcc,因此当您安装 gcc49 时,它会在命令行上调用 gcc-4.9。这是为了防止干扰由 OSX 命令行开发工具链提供的 gcc 存根(实际上是 clang),并允许您安装 gcc-4.8gcc-4.7,等等。

通常定义环境变量 CC=gcc-4.9CXX=g++-4.9 应该允许您使用 gcc-4.9 编译器编译基于 autoconf 的包,以及基于标准 makefile 的项目,而不是使用默认 cc/gcc.