-1

It's a well-known fact that the g++ command actually links to clang++, from the llvm toolkit. Problem is, every makefile that uses g++ has to point explicitly to the location, and unless my end user has brew on linux, the path will be different.

So my question is, how do I set the system up, so that /bin/g++ actually points to a version installed from either macports or homebrew.

I know that Apple have deprecated GNU C Compiler a long time ago, and that this is the way it has been, but creating a hard-link to clang is the most stupid solution I could think of, and I'd like to have my system working as it should.

  • This is why automaker,waf,scones and cmake do tests to find c++ and other tools and their capabilities so that they build on machines with different paths. Simple makefiles are not sufficient. – Mark Sep 10 '18 at 19:11
  • How about if I wrote a maths textbook where both 4 and 5 meant 5. And that’s not Really a problem, since every time you mean 4, you could write 3+1. And yeah calculators understand this, and will give you the right results, which is why knowing how to count is not sufficient. – Alex Petrosyan Sep 10 '18 at 20:27
  • Different machines have different C++ compilers and they are in different places. e.g. on one box you have /opt/bin/cc amd /usr/bin/cc - you cannot assume that the C++ compiler is in /usr/bin/g++ – Mark Sep 10 '18 at 20:36
  • @Mark, you’re missing the point. I’m fine with compilers having different locations based on installation method. I’m fine with there being no way of installing gcc on Mac OS, but I’m not fine with masquerading llvm as GCC and calling that a solution. You’re absolutely right, I can’t assume that a compiler is at one location, but I usually don’t have to. The OS knows where it is installed, and usually it doesn’t lie to your face about the location. – Alex Petrosyan Sep 11 '18 at 5:11
  • The OS does not know where the compiler is it does mot tell you at all anythjing about the compiler. If I want gcc I use macports and could have several versions around at once so have to choose the one I want. (When I learnt C++ the comment was always compile under two different compilers to get the best error messages and make sure you were writing standard code.) There is no one place for a compiler – Mark Sep 11 '18 at 10:50
0

You just need to run this command in the Terminal:

ln -f /usr/local/bin/g++-8.2.0 /bin/g++

where you need to replace "/usr/local/bin/g++-8.2.0" with the actual full path to the g++ executable, you want to use. This varies depending on if you use macports or homebrew, what you set your homebrew prefix to, which version of g++ you install, etc.

  • ln: /bin/g++: Operation not permitted. I even tried sudo rm -rf /bin/g++ to remove the hardlink. It exits with 0 (as if it had removed the hardlink), but which g++ still brings you the same file. – Alex Petrosyan Sep 10 '18 at 14:21
  • You’ll need to disable SIP to make changes to system files. Reboot in recovery mode, issue the command in my answer after disabling SIP and then re-enable it. – jksoegaard Sep 10 '18 at 17:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .