Using Homebrew with alternate GCC

前端 未结 4 880
走了就别回头了
走了就别回头了 2020-12-04 20:47

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. Specifi

相关标签:
4条回答
  • 2020-12-04 20:48

    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.

    0 讨论(0)
  • 2020-12-04 20:49

    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

    0 讨论(0)
  • 2020-12-04 20:50

    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
    
    0 讨论(0)
  • 2020-12-04 20:55

    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.

    0 讨论(0)
提交回复
热议问题