macOS, Homebrew, and gcc

sweenish

Diamond Member
May 21, 2013
3,656
60
91
I recently got a MBP for work, and have been working on getting it set up. I like to do most of my work in VS Code, and so I got the pre-requisite stuff installed. Full Xcode in order to install homebrew, and brew versions of gcc and make. The only brew packages I have installed are gcc, git, and make.

I have also placed the appropriate aliases in ~/.bash_profile and added the main brew directory to my PATH.
Code:
# A snippet of my ~/.bash_profile
export PATH=/usr/local/Cellar:$PATH

# An example alias
alias g++='g++-7'

So, if I open my terminal app and type g++ --version, it reports back using the brew g++, which is exactly what I want.

VS Code's integrated terminal also provides the desired output when I type g++ --version, but this is where things get weird for me.

Executing a makefile from within VS Code's terminal (or any terminal for that matter) calls clang, Xcode's compiler. Not my brew compiler.

I am doing my work from a user account, brew stuff is installed via an admin account.

Hopefully someone knows the missing piece of my puzzle.
 

sweenish

Diamond Member
May 21, 2013
3,656
60
91
Just for reference, here is the solution.

Homebrew is very careful about not replacing the baked in tools, as it should be. So, the brew g++ goes by g++-7. That's tedious and would make my makefiles very platform specific.

So, as opposed to all the stuff I had done, all I had to do was create symlinks in /usr/local/bin that look like the following:
Code:
# Sample symlink command
ln -s g++-7 g++

Now, when I type 'which g++', I get the proper brew version. git was not renamed, so no need there. I added links for the other c++ compiler aliases c++ and cpp, and one for make. All is working fine, and if I decide I want to use clang, it's still there for me.

I feel like if I had done a better job with the brew documentation, I could have avoided this headache and lost time and got going right away, but whatever. It's working now, as intended.