One way of having an additional gcc version is to install the new version into either /usr/local or /opt. I have GCC 6.3.0 installed into /opt for MATLAB.
I based my build script off the official Slackware SlackBuild in the source tree. Download gcc-6.3.0.tar.bz2 and extract it. Then create a build directory and put do_build.sh in it:
Code:
#!/bin/sh
srcdir=../gcc-6.3.0
destdir=/opt/gcc-6.3.0
SLKCFLAGS="-O2 -fPIC"
LIBDIRSUFFIX="64"
LIB_ARCH=amd64
TARGET=x86_64-slackware-linux
NUMJOBS=" -j 8 "
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
"$srcdir/configure" \
--prefix=$destdir \
--libdir=$destdir/lib$LIBDIRSUFFIX \
--enable-bootstrap \
--enable-languages=c,c++,fortran,go,lto,objc,obj-c++ \
--enable-threads=posix \
--enable-checking=release \
--enable-objc-gc \
--with-system-zlib \
--enable-libstdcxx-dual-abi \
--with-default-libstdcxx-abi=gcc4-compatible \
--with-python-dir=/lib$LIBDIRSUFFIX/python2.7/site-packages \
--disable-libunwind-exceptions \
--enable-__cxa_atexit \
--enable-libssp \
--enable-lto \
--disable-install-libiberty \
--with-gnu-ld \
--verbose \
--with-arch-directory=$LIB_ARCH \
--disable-gtktest \
--disable-multilib \
--target=${TARGET} \
--build=${TARGET} \
--host=${TARGET} || exit 1
make $NUMJOBS bootstrap;
( cd gcc || exit
make $NUMJOBS gnatlib GNATLIBCFLAGS="$SLKCFLAGS"
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
make $NUMJOBS gnattools
)
make info
make install || exit 1
Now to use it just put /opt/gcc-6.3.0/bin at the beginning of your PATH (that's what my MATLAB startup script does).
You'll probably have to fiddle with the build options for different versions of GCC.