0

How can I ensure that gcc points to a particular compiler? Can I make a permanent symbolic link to the xcode version of gcc?

I have several versions of the gcc compiler installed on my system, including

`gcc-11` found at `/usr/local/gcc-10/share` (compiled from source following these [instructions][1])
`gcc-9.3.0` found at `/usr/local/Cellar/gcc/9.3.0_1/share`
`gcc-4.8.5` found at `/Users/PatrickT/miniconda/pkgs/gcc-4.8.5-8/share`

The default version is gcc-4:

gcc --version
gcc (GCC) 4.8.5
which gcc
/Users/PatrickT/miniconda/bin/gcc

This miniconda version of gcc is not working for me. If I remove miniconda from the PATH, my system reverts to another version of gcc and everything works as expected. However, I do use miniconda's Python and would therefore like to keep it on my PATH. In my .zhrc profile (apparently, MacOS Catalina has moved the .bashrc to .zhrc), I have:

export PATH="/Users/PatrickT/miniconda/bin:$PATH"
export PATH="/usr/local/bin:$PATH"
export PATH="/usr/local/Cellar/gcc:$PATH"
export PATH="/usr/local/gcc-10/bin:$PATH"

I have tried to change the order of these lines, but it has made no difference: miniconda's gcc remains the default compiler, unless I remove the first line completely, but then... I'm unable to use conda's Python!

Background: I'm not using the gcc directly, but I appear to need it to compile certain scripts. I have both the xcode command line tools and the xcode application, if that matters. I'm on MacOS Catalina 10.15.4.

PatrickT
  • 10,037
  • 9
  • 76
  • 111
  • Your problem is a perfect example why making conda available via `conda init ` is preferable over adding `/bin` to your path directly. :-) – cel May 18 '20 at 19:07
  • 1
    I must admit that I am not very familiar with the mechanism spyder finds conda environments, but I am fairly confident it will work fine with the new `conda init` way of making conda available. Note, that the preferred way to make conda available used to be putting `/bin` into PATH, that's why you found the comment there. See https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#conda-init for details. – cel May 19 '20 at 07:35
  • @cel, Thanks for the tips. I have cleaned up my system as much as I could by removing and reinstalling compilers and Python distributions. It took a great deal of slewthing to find and remove/change symlinks to old things. I am currently using a conda environment, but I'm not sure how much that helps... The Anaconda/Miniconda docs recommend setting up an environment and not adding to PATH, but then it complains that you have to run `conda init` and that puts conda on the PATH. Oh well... – PatrickT May 21 '20 at 17:07

2 Answers2

1

Until a knowledgeable person answers this question, here is some food for thought:

  • cc is a symbolic link to gcc.

  • CC is an environment variable referring to the system's C compiler.

  • gcc is a symbolic link to a compiler.

  • A typical default is CC=cc, where cc is usually a symlink to gcc.

  • You can change the invocation for a particular task by setting CC?=gcc or CC=gcc. The ?=' operator is a conditional variable assignment operator: will have an effect only if the variableCCis not yet defined. The=operator will supersede any previously set link. OrCC=gcc-10` to invoke a particular version insalled on your system.

  • CC could be a link to clang (MacOS) or g++ (Linux). See this answer to a related question, particularly Jonathan Leffler's answer and the comment by Josh Kodroff.

References: GNU Manual on Implicit Variables, GNU Manual on Make.

PatrickT
  • 10,037
  • 9
  • 76
  • 111
0

Until a better solution comes along, you can remove Anaconda's gcc with

    conda remove gcc

And check that your system is now picking up from Xcode

    gcc --version
    Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
    Apple clang version 11.0.3 (clang-1103.0.32.59)
    Target: x86_64-apple-darwin19.4.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
PatrickT
  • 10,037
  • 9
  • 76
  • 111