Recommended way to provide another version of GCC?

6

4

I'm on Fedora 23 which installs GCC 5.3.1 by default.

For a cross compilation project with libraries which have been compiled with GCC 4.9 I'd like to install GCC 4.9 in parallel.

This (very old) post describes how to do this for GCC 3.8 and recommends to build any other version from scratch.

Now it's 3 years later - Is there a way to provide an older version of GCC in a separate directory (using the package manager) which can be used in parallel to the installed GCC 5.3?

frans

Posted 2016-02-10T15:07:04.990

Reputation: 691

2

GCC 4.9 is not packaged explicitly in official repository. So you will probably have to build it on your own. You can use the compat-gcc packages as an example

– Jakuje – 2016-02-10T17:34:11.600

Answers

8

This is NOT an answer to my question since I only show how to build and use GCC 4.9 in a way which works on Fedora 23 (and on any other platform probably, too). It's only the compilation of steps I had to do to compile with another version of GCC than the shipped one.

The shown steps are taken from here.

  • lookup and download and exctract the appropriate archive from http://www.gnu.org/software/gcc/mirrors.html:

    wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-4.9.3/gcc-4.9.3.tar.bz2
    mkdir src; cd src
    tar xf ../gcc-4.9.3.tar.bz2
    
  • download prerequisites:

    cd gcc-4.9.3
    ./contrib/download_prerequisites
    
  • configure the build (add --disable-multilib when you don't need a 32 bit build, set the install-prefix, add/remove languages):

    mkdir ../objdir; cd ../objdir
    ../gcc-4.9.3/configure \
        --prefix=`pwd`/../../gcc-4.9.3-x86_64 \
        --enable-languages=c,c++ \
        --disable-multilib
    
  • actually build and install GCC:

    make -j4
    make install
    

You can now use this new compiler by just setting CC (maybe also CXX) before you run make or cmake:

export CC=</installation/path/to/gcc>/bin/gcc
make .

or

CC=</installation/path/to/gcc>/bin/gcc cmake <path>

frans

Posted 2016-02-10T15:07:04.990

Reputation: 691