I recently built an older version of GCC and installed it in my home directory (spec. ~/local/gcc-5.3.0
). However, I need this compiler only for CUDA projects, and will be working with the system compiler (GCC 6.2.1) rest of the time. So, I guess I need to find a way to switch between these as and when needed, and in a way that also changes the library and include paths appropriately.
I understand that update-alternatives
is one way to do so, but it seems to require root permissions to be set up, which I don't have.
The next best thing might be to write a shell function in .bashrc
that ensures the following:
Each call switches between system and local gcc
Whenever a switch is made, it adjusts paths so that when local gcc is chosen, it first looks for header files and libraries that were installed by itself before looking in system paths like
/usr/local/include
orusr/local/lib
. A previous answer suggests that modifyingLD_LIBRARY_PATH
should be sufficient, because a GCC installation "knows" where its own header files and static libraries are (I am not sure if it's correct, I was thinking I might need to modifyCPATH
, etc).
Is the above the best way to achieve this? If so, what paths should I set while implementing such a function?