macos 将 Homebrew 与备用 GCC 一起使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9186033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:50:53  来源:igfitidea点击:

Using Homebrew with alternate GCC

macosgcchomebrew

提问by Andrew Spott

I've installed gcc-4.6using the homebrew-alternatives gccformula, but I can't seem to get it to use that GCC to install other formulas. Specifically Open-MPI and boost.

我已经gcc-4.6使用homebrew-alternatives gcc公式安装了,但我似乎无法让它使用该 GCC 来安装其他公式。特别是 Open-MPI 和 boost。

Does anyone know how to make Homebrew use this new compiler?

有谁知道如何让 Homebrew 使用这个新的编译器?

Thanks!

谢谢!

采纳答案by Tom Close

These answers are all fairly old now. It seems that recent versions of homebrew have a '--cc' option that enables you to select the c compiler to use. For example

这些答案现在都相当老了。似乎最新版本的自制软件有一个“--cc”选项,使您可以选择要使用的 c 编译器。例如

brew install --cc=gcc-6 <package-name>

will install using the brew version of gcc

将使用 brew 版本的 gcc 安装

回答by 2bits

Homebrew can't adapt to other versions of gcc using command line options. You can easily override the older compiler, though, if you edit the open-mpi and boost formula. For example, you can add a few commands after the "def install" in open-mpi.rb:

Homebrew 无法使用命令行选项适应其他版本的 gcc。但是,如果您编辑 open-mpi 和 boost 公式,您可以轻松覆盖旧的编译器。例如,你可以在 open-mpi.rb 中的“def install”之后添加一些命令:

  def install
    # Force compilation with gcc-4.6
    ENV['CC'] = '/usr/local/bin/gcc-4.6'
    ENV['LD'] = '/usr/local/bin/gcc-4.6'
    ENV['CXX'] = '/usr/local/bin/g++-4.6'

    # Compiler complains about link compatibility with FORTRAN otherwise
    ENV.delete('CFLAGS')
    ENV.delete('CXXFLAGS')

That worked for me on Lion. Good luck.

这对我在 Lion 上有用。祝你好运。

回答by rcv

It looks like the latest versions of Homebrew now support the HOMEBREW_CCand HOMEBREW_CXXenvironment variables.

看起来最新版本的 Homebrew 现在支持HOMEBREW_CCHOMEBREW_CXX环境变量。

So now you can do the following:

所以现在您可以执行以下操作:

$ HOMEBREW_CC=gcc-4.2 HOMEBREW_CXX=g++-4.2 brew install ice

回答by blahdiblah

From their wikiit sounds like they don't support other compilers:

他们的 wiki听起来他们不支持其他编译器:

Installing a custom version of GCC or autotools into the $PATH has the potential to break lots of compiles. So we stick to the Apple-provided compilers.

在 $PATH 中安装自定义版本的 GCC 或 autotools 有可能破坏大量编译。所以我们坚持使用 Apple 提供的编译器。