7

I wanted to install updated version of gcc on a server where I do not have root access. I tried conda install -c creditx gcc-7 which was not working. Then I found conda install -c anaconda gcc_linux-64 in fact installs gccv7.3. But after the successful installation, the conda environment still uses the system gcc at /usr/bin/gcc

Please help me so that I can use the gcc v7.3 that I just installed.

deltasata
  • 377
  • 1
  • 4
  • 21
  • 1
    How do you know that `/usr/bin/gcc` is still used? What program are you using to compile your C code (make, SCons, CMake, etc.)? Or are you just running `gcc name-of-c-file.c`? You need to give many more details about how you're actually running everything or it will be very hard to answer. – darthbith Dec 11 '19 at 14:08
  • Maybe you can try to create a environment and ativate the environment? – r0n9 Apr 10 '21 at 14:51

1 Answers1

15

As explained here: https://docs.conda.io/projects/conda-build/en/latest/resources/compiler-tools.html

1) All of the executables in a compiler package are "prefixed." Instead of gcc, the executable name of the compiler you use will be something like x86_64-conda_cos6-linux-gnu-gcc

2) Many build tools such as make and CMake search by default for a compiler named simply gcc, so we set environment variables to point these tools to the correct compiler.

So if you run:

conda create -n cc_env gcc_linux-64
conda activate cc_env
ls $CONDA_PREFIX/bin

You will see a bunch of compiler tools with the prefixed name:

c89                                    x86_64-conda_cos6-linux-gnu-ct-ng.config  x86_64-conda_cos6-linux-gnu-gcov-dump  x86_64-conda_cos6-linux-gnu-objdump
c99                                    x86_64-conda_cos6-linux-gnu-dwp           x86_64-conda_cos6-linux-gnu-gcov-tool  x86_64-conda_cos6-linux-gnu-ranlib
x86_64-conda_cos6-linux-gnu-addr2line  x86_64-conda_cos6-linux-gnu-elfedit       x86_64-conda_cos6-linux-gnu-gprof      x86_64-conda_cos6-linux-gnu-readelf
x86_64-conda_cos6-linux-gnu-ar         x86_64-conda_cos6-linux-gnu-gcc           x86_64-conda_cos6-linux-gnu-ld         x86_64-conda_cos6-linux-gnu-size
x86_64-conda_cos6-linux-gnu-as         x86_64-conda_cos6-linux-gnu-gcc-ar        x86_64-conda_cos6-linux-gnu-ld.bfd     x86_64-conda_cos6-linux-gnu-strings
x86_64-conda_cos6-linux-gnu-cc         x86_64-conda_cos6-linux-gnu-gcc-nm        x86_64-conda_cos6-linux-gnu-ld.gold    x86_64-conda_cos6-linux-gnu-strip
x86_64-conda_cos6-linux-gnu-c++filt    x86_64-conda_cos6-linux-gnu-gcc-ranlib    x86_64-conda_cos6-linux-gnu-nm
x86_64-conda_cos6-linux-gnu-cpp        x86_64-conda_cos6-linux-gnu-gcov          x86_64-conda_cos6-linux-gnu-objcopy

This is ok because environment variables like CC and CPP are pointing to the compiler to use, and commands like make know to use these variable:

$ echo $CC
/home/builder/anaconda3/envs/cc_env/bin/x86_64-conda_cos6-linux-gnu-cc
$ echo $CPP
/home/builder/anaconda3/envs/cc_env/bin/x86_64-conda_cos6-linux-gnu-cpp

For more info on what environment variables make is aware of see: https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html

William D. Irons
  • 2,244
  • 1
  • 18
  • 19
  • 1
    For some reason `cmake` refused to use the compiler installed in my conda environment, despite `echo $CC` pointing to the conda-installed compiler. For future self and anybody else: a definition flag can be used to point `cmake` to a specific compiler. E.g. `cmake .. -DCMAKE_C_COMPILER=CONDA-PREFIX/envs/ENV-NAME/bin/x86_64-conda-linux-gnu-gcc` – L_W Sep 11 '20 at 18:05