I am trying to compile some code within a Conda environment, where I
previously installed the compiler package gcc_linux-64
.
However, even after deactivating and reactivating again the environment,
gcc
is still /usr/bin/gcc
.
What should I do to have Conda working as expected, ie. using the tool
I install ? Like it is for other software like git
or whatever.
Any help would be appreciated, thanks in advance !
If you do:
export CONDA_BUILD=1
conda activate <name-of-env-in-which-gcc_linux-64-is-installed>
You will see:
INFO: activate-binutils_linux-64.sh made the following environmental changes:
+ADDR2LINE=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-addr2line
+AR=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-ar
+AS=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-as
+CXXFILT=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-c++filt
+ELFEDIT=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-elfedit
+GPROF=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-gprof
+LD=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-ld
+LD_GOLD=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-ld.gold
+NM=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-nm
+OBJCOPY=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-objcopy
+OBJDUMP=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-objdump
+RANLIB=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-ranlib
+READELF=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-readelf
+SIZE=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-size
+STRINGS=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-strings
+STRIP=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-strip
INFO: activate-gcc_linux-64.sh made the following environmental changes:
+CC=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-cc
+CFLAGS=-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -I/include -fdebug-prefix-map=${SRC_DIR}=/usr/local/src/conda/${PKG_NAME}-${PKG_VERSION} -fdebug-prefix-map=${PREFIX}=/usr/local/src/conda-prefix
+CPP=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-cpp
+CPPFLAGS=-DNDEBUG -D_FORTIFY_SOURCE=2 -O2
+DEBUG_CFLAGS=-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-all -fno-plt -Og -g -Wall -Wextra -fvar-tracking-assignments -pipe -I/include -fdebug-prefix-map=${SRC_DIR}=/usr/local/src/conda/${PKG_NAME}-${PKG_VERSION} -fdebug-prefix-map=${PREFIX}=/usr/local/src/conda-prefix
+DEBUG_CPPFLAGS=-D_DEBUG -D_FORTIFY_SOURCE=2 -Og
+GCC=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-gcc
+GCC_AR=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-gcc-ar
+GCC_NM=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-gcc-nm
+GCC_RANLIB=/root/m3/envs/test/bin/x86_64-conda_cos6-linux-gnu-gcc-ranlib
+LDFLAGS=-Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,-rpath,/lib -L/lib
+_CONDA_PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_x86_64_conda_cos6_linux_gnu
In your make file, you could use variables like $CC
instead.
The issue is the name of the gcc compiler that conda installs. Because it isn't just gcc
, it's some long complicated thing, eg. x86_64-conda_cos6-linux-gnu-gcc
, it won't override the system executable, even if your conda directory is earlier in your PATH
variable.
The solution is to softlink your conda gcc compiler into your local binary directory, eg. ln -s path/to/conda/gcc ~/.local/bin/gcc
, and then put that ahead of your system binary directory in your PATH
variable, eg. export PATH=$HOME/.local/bin:$PATH
where your shell is sourced, ie. ~/.bashrc
, ~/.bash_profile
, ~/.zshrc
, etc.
This will then point to your conda executable before the system one, and should have the appropriate name to override it.
Keep in mind that if you delete your environment, or replace / update the gcc installed in it, you will need to update the softlink accordingly. Unless you need lots of different gcc versions, I'd just install it to your base env, do the soft link, and don't touch it after that. Hacky, but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With