Ubuntu – How to install gcc-5.3 on Ubuntu 16.04

16.04aptgccppa

I'm currently running Ubuntu 16.04 and want to install gcc-5.3 from source, without disrupting thegcc-5.4 and gcc-4.9 that I have already installed using Synaptic package manager.

The reason I want gcc-5.3 is I'm using CUDA 8.0 RC, which doesn't support gcc versions after 5.3. Rather than downgrading to 4.9, I'd like to install (or at least know how to install) 5.3. I already have the code for gcc-5.3 and only need to go through the configure/make/make install ritual.

Now, I need to understand the various configure options before running make and make install. I particularly want to be certain that I install gcc-5.3 in the right place and don't interfere with my existing gcc-5.4 and gcc-4.9.

I found one account of how to configure 5.3, that was as follows:

 ./gcc-5.3.0/configure --disable-checking --program-suffix=-5.3 --enable-languages=c,c++,go,objc --disable-multilib --with-system-zlib prefix=/usr/local/gcc-5.3

Some of these options make sense, others don't. Specifically, the options I think I understand well enough to not mess myself up are:

--disable-checking: Will make the installation quicker, but at the risk 
                    of missing errors. Since I'm paranoid, I'll probably 
                    omit this option.

--disable-multilib: I don't understand this. I gather it has something 
                    to do with variations on the compiler's target machine,
                    but that's all I can gather. 
                    At worst, if I omit this option, I think I'll just
                    end up with some extra libraries, which doesn't seem 
                    so bad. Why do/don't I want to use this?

--with-system-zlib: Use the zlib that I already have with my system, 
                    rather than gcc's version. This seems reasonable to 
                    me.

--enable-languages=c,c++,go,objc: AFAIK, I'm really just interested in c & c++, 
                   so this option seems pretty harmless, although I might 
                   just use --enable-lnguages=all, since it can't hurt.

The options that do worry me are:

--program-suffix=-5.3: This seems just to add a -5.3 suffix 
                       at the end of the installation path, 
                       which is probably a good idea if I get the 
                       path right

prefix=/usr/local/gcc-5.3: This just seems to specify the 
                           installation directory and to make the 
                           --program-suffix=-5.3 specification 
                           redundant. However, it is the option that 
                           makes me the most uneasy. 

When I do a find . -name gcc, the only relevant paths I see are /usr/lib/gcc and /usr/bin/gcc

In /usr/lib/gcc, there are two sub-directories – i686-linux-gnu and x86_64-linux-gnu, since I have a 64-bit machine, I looked in the x64 directory.

There, I saw a soft-link – 4.9.3, that linked to a directory called 4.9, that had files for gcc-4.9. Similarly, I saw a softlink called 5.4.0 that linked to a directory called 5, that had files for gcc-5.4. So, I expect that I want to use prefix=/usr/lib/gcc/5.3 and not use the --program-suffix option. Is this correct?

At this point, I'm just assuming that when I run make & make install that the .a & .so files will get placed in /usr/lib/gcc/5.3 and that the executable will end up as /usr/bin/gcc-5.3 and that I'll be able to use Ubuntu's update-alternatives to move among gcc-5.4, gcc-5.3 and gcc-4.9

(Note: the reason I'm not using Synaptic is that it only provides gcc-5.4, which it calls gcc-5. Similarly, the ppa ppa:ubuntu-toolchain-r/test refers to all versions of gcc-5.X as gcc-5, which also seems dangerous to use. I suspect the decision to refer to all minor versions of gcc-5.x as gcc-5 is the root of my problems)

Best Answer

You don't need to install gcc=5.3 from source in that case. You can use a conda environment (install Miniconda or Anaconda) and install gcc_linux-64=5.3.