Linuxbrew switch default gcc version

Hi! I am using linuxbrew for a few packages, but I found that it uses gcc 5.5, and I need a more recent version. At least gcc6. Is there an option to switch it?

You can install gcc to install gcc 9.

Yes, I can install gcc@9 or gcc@7, but I can’t find the way to make it as default one =(

There is only a default GCC in the sense that the formula are compiled with one if no others exist. If you want to use a different compiler with a formula you can just depend on another compiler in the formula. What is the problem you are trying to solve with this?

I am trying to build one of my packages for ROS, and seems like ROS supports only gcc 6+ (at least it is building with it).
And because linuxbrew is first in my PATH variable it is taking gcc from there. I was thinking to change it by default so I don’t have to modify my PATH so I can use linuxbrew’s gcc.

@kumuji What tool are you using to build your package?

What are possible ways to tell it where gcc is without having to modify your PATH?

I am using catkin_tools which is a python tool to automate building of ros packages. As far as I know it is calling CMake files in each of the package. I guess I can also specify -DCMAKE_ flags for the correct compiler, but I thought of easier solution to just changing default gcc on the system(which is from brew). But if it is not trivial, I can think of something different.
Thank you for help!

1 Like

First try

brew install gcc@9
export CC=gcc-9 CXX=g++-9
./configure && make # or whatever build script

If that doesn’t work try, try the command line options of the build script to set the preferred compiler.

If that doesn’t work, you can try…

ln -sf gcc-9 ~/.linuxbrew/bin/gcc
ln -sf g++-9 ~/.linuxbrew/bin/g++
ln -sf gcc-9 ~/.linuxbrew/bin/cc
ln -sf g++-9 ~/.linuxbrew/bin/c++