Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to permanently override HOMEBREW_CC and HOMEBREW_CXX settings?

Since I installed gcc-49 on my Mac I can't get Homebrew to find the C++ compiler anymore. It always fails with error messages like:

configure: error: C++ preprocessor "/lib/cpp" fails sanity check

Running "brew upgrade -v" spits out this:

...
==> ENV
HOMEBREW_CC: llvm-gcc
HOMEBREW_CXX: llvm-g++
...

I have no idea why Homebrew wants to use these compilers. Why can't it use the normal CC/CXX environment variables like everything else?

I already found, that by editing the formula directly like described in Using Homebrew with alternate GCC, I can change the HOMEBREW_CXX to use /usr/local/bin/g++ for example, which makes compiling formulas that need C++ work again.

But I don't want to edit every single formula by hand for the rest of my days. How can I change this HOMEBREW_CXX environment variable permanently? I tried setting them in my .bash_profile and running "export HOMEBREW_CXX=..." in the console and neither of those work, only editing the formula directly.

Does anyone have an idea?

like image 239
Chad3000 Avatar asked Apr 28 '14 10:04

Chad3000


1 Answers

A poor man's solution, to be sure, but this works: put an alias in your .bashrc or .bash_profile:

alias brew='HOMEBREW_CC=gcc-4.8 HOMEBREW_CXX=g++-4.8 brew'

Now, whenever you use brew it will use the compilers you want. Check that it works by doing:

brew --env
HOMEBREW_CC: gcc-4.8
HOMEBREW_CXX: g++-4.8
...

HTH

like image 90
josephwb Avatar answered Nov 09 '22 06:11

josephwb