3

I want to use the gnu compiler collection instead of the x-code compiler to compile some bioinformatics tools on the mac, which did compile on Linux but fails to build on macOS.

I did install homebrew

$ brew install gcc

$ cd /usr/local/bin
$ sudo ln -s /opt/homebrew/bin/gcc-11 gcc

$ /usr/local/bin/gcc
gcc: fatal error: no input files
$ which gcc
/usr/local/bin/gcc

However, calling gcc without the path still points to clang.

$ gcc
clang: error: no input files

How can I point gcc and g++ to the gnu compiler collection?

2
  • Did you open a new Terminal tab after installing gcc? What does type gcc say, and echo $PATH?
    – nohillside
    Commented Jan 26, 2022 at 21:02
  • @nohillside Before reopening the terminal type gcc was: $ type gcc gcc is hashed (/usr/bin/gcc) reopening the terminal did help indeed. Thank you :-)
    – witek
    Commented Jan 26, 2022 at 21:14

2 Answers 2

1

The shell hashes (caches) paths to binaries. So if you run gcc before installing a new version in a different path, it will still use the previous/remembered version. To fix, either clear the stored path (check the hash command in the man page of your shell) or simply open a new Terminal tab.

1

You don't mess around with getting gcc on your PATH. You don't point g++ to the compiler you want.

You alter your build system - usually a Makefile, CMake, autoconf or Xcode to build using the C compiler you want. (This also allows different projects to use different compilers)

4
  • What's so scary about customizing PATH? Setting your own PATH isn't "messing around". For the sake of efficiency, isn't pointing g++ to the compiler you want the best behavior? With the most frequently used g++ in your PATH, you can still alter your build system to use any other C compiler you want. Isn't this the most convenient way? Commented Nov 7, 2022 at 9:35
  • It is not scary but the point is when building c++ programs you don't rely on the path for gcc. You control the environment via your build script - e.g. makefile, Xcode project, CMAKE file etc and not the PATH. It would be best if the default was to fail and you explicitly set which compiler to use.
    – mmmmmm
    Commented Nov 7, 2022 at 10:21
  • Thanks for the comment! I see your point. Maybe because I usually don't work with many different compilers, I do prefer a desired default gcc in the path. This preference also pushed me toward MacPorts, even though I use both. Commented Nov 7, 2022 at 18:08
  • Having just one C compiler was a feature of NeXTStep and early Linux before clang existed, other Unixes usually had at their own C plus gcc
    – mmmmmm
    Commented Nov 7, 2022 at 21:13

You must log in to answer this question.

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