Jean-Pat Jean-Pat - 1 year ago 101
Linux Question

how to switch between gcc versions to build torch7 or caffe with cudnn 5 acceleration (cuda 7.5) on manjaro linux?

I try to build torch7 or caffe with cudnn5 support using cuda 7.5 on manjaro linux.

Both gcc 6.1 and gcc 4.9 are available. gcc 6.1 is incompatible with cuda 7.5,leading to errors when building torch7 and caffe with cudnn 5 support.

gcc4.9 was installed from AUR repository:

jeanpat@dip4fish ~]$ whereis gcc-4.9
gcc-4: /usr/bin/gcc-4.9
[jeanpat@dip4fish ~]$ whereis g++-4.9
g++-4: /usr/bin/g++-4.9
[jeanpat@dip4fish ~]$ whereis g++
g++: /usr/bin/g++ /usr/share/man/man1/g++.1.gz
[jeanpat@dip4fish ~]$ whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/share/man/man1/gcc.1.gz /usr/share/info/

The idea was to switch from gcc6.1 to gcc4.9 before compilation with:

jeanpat@dip4fish ~]$ export CC=/usr/bin/gcc-4.9
[jeanpat@dip4fish ~]$ export CXX=/usr/bin/g++-4.9

But when gcc is invoqued, this is still the 6.1 version:

[jeanpat@dip4fish ~]$ gcc --version
gcc (GCC) 6.1.1 20160602

.bashrc was modified so that:


How to temporary switch to gcc 4.9 transparently (without modifying the makefile or the script of caffe and torch7)?

Answer Source

If you don't want to change any files, this hack can be used :

cd /usr/bin/
mv gcc gcc-6.1-back
mv g++ g++-6.1-back
ln -s gcc-4.9 gcc
ln -s g++-4.9 g++

... Then it's fairly easy to revert to "6.1" .... delete the links, etc.

If Manjaro has the /etc/alternatives/ mechanism, you can "install" both gcc versions to /etc/alternatives/ , like this java example When and Why run alternatives --install java jar javac javaws on installing jdk in linux .... and switch version with a single command, + one setting.