Using Homebrew with alternate GCC

2019-01-13 13:55发布

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

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

Thanks!

4条回答
小情绪 Triste *
2楼-- · 2019-01-13 14:35

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

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

will install using the brew version of gcc

查看更多
虎瘦雄心在
3楼-- · 2019-01-13 14:42

It looks like the latest versions of Homebrew now support the HOMEBREW_CC and HOMEBREW_CXX environment variables.

So now you can do the following:

$ HOMEBREW_CC=gcc-4.2 HOMEBREW_CXX=g++-4.2 brew install ice
查看更多
冷血范
4楼-- · 2019-01-13 14:54

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

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.

查看更多
欢心
5楼-- · 2019-01-13 14:57

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:

  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.

查看更多
登录 后发表回答