GCC 4.7 (via brew) keeps including from “/usr/include/c++/4.2.1”

developmentgcchomebrew

This one is driving me crazy:

I need to use lot of stuff which simply does not compile with the standard clang/llvm compilers which come with Xcode 5 (on Mac OS X 10.8), so I decided to install gcc47 via brew.

Everything went fine but when I try to compile things, I get several error messages and I discovered that some includes are still coming from "/usr/include/c++/4.2.1", which is really weird.

Can anyone explain me how to set it up in a clean way?

These are the step I was doing:

  • brew update
  • brew install gcc47
  • alias gcc='gcc-4.7'

brew warned me that I have to set up LDFLAGS and CPPFLAGS, quoting (summarised):

  This formulas are keg-only: so they were not symlinked into /usr/local.
    Conflicts with gmp, mpfr, libmpc, ppl in main repository.

    Generally there are no consequences of this for you. If you build your
    own software and it requires these formulas, you'll need to add to your
    build variables:
        LDFLAGS:  -L/usr/local/opt/gmp4/lib
        CPPFLAGS: -I/usr/local/opt/gmp4/include

        LDFLAGS:  -L/usr/local/opt/mpfr2/lib
        CPPFLAGS: -I/usr/local/opt/mpfr2/include

        LDFLAGS:  -L/usr/local/opt/libmpc08/lib
        CPPFLAGS: -I/usr/local/opt/libmpc08/include


        LDFLAGS:  -L/usr/local/opt/ppl011/lib
        CPPFLAGS: -I/usr/local/opt/ppl011/include

        LDFLAGS:  -L/usr/local/opt/cloog-ppl015/lib
        CPPFLAGS: -I/usr/local/opt/cloog-ppl015/include

So exporting LDFLAGS and CPPFLAGS via

        export LDFLAGS="${LDFLAGS} -L/usr/local/opt/gmp4/lib -L/usr/local/opt/mpfr2/lib -L/usr/local/opt/libmpc08/lib -L/usr/local/opt/ppl011/lib -L/usr/local/opt/cloog-ppl015/lib"

        export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/gmp4/include -I/usr/local/opt/mpfr2/include -I/usr/local/opt/libmpc08/include -I/usr/local/opt/ppl011/include -I/usr/local/opt/cloog-ppl015/include"

should do the trick (I thought).

But it doesn't. I keep getting messages like:

/usr/include/c++/4.2.1/bits/stl_vector.h:600:7: note: must qualify
identifier to find this declaration in dependent base class
push_back(const value_type& __x)
^

and I simply don't understand why?

Best Answer

that note just refers to the 4 libraries gmp, mpfr, libmpc, ppl and I think means that if you use these they need to be before the standard search path.

Your issue is where is the compiler looking for standard library headers (and later libraries). gcc defaults to /usr/include which is installed for Apple's compilers and that gets redirected by version to the path you see.

You need to explicitly set the paths to look in the hombrew compilers path first