LAMP 2019Linux

Development Tools – Building a LAMP Server (2019)

This is the fourth article in a series on building the ultimate LAMP Server. Here we will cover setting up development tools for use in compiling software. While most distributions come with a set of development tools you can install from their repository, there are some that we may wish to compile manually, usually because the distribution contains very old versions.

Important: you can probably skip most of this article for Fedora and Arch Linux, since those distributions tend to have more recent packages. But at the minimum, do the Essentials section and carefully read the notes in the GCC section. The GCC section is what will take the most time, which is why I have placed it last.

Estimated time (this post only): 5 minutes to 10+ hours
* varies depending on whether you choose to compile everything listed from source and how many processor cores you have

Essentials

There are a few essential tools you may need that you should download from the repository first. You may already have some of these installed, but let’s check anyway (technically, you may not even need half of these depending on what you compile, but this should minimize any possible errors).

CentOSFedoraUbuntu/DebianopenSUSEArch Linux
sudo yum install make automake autoconf gcc wget dkms bzip2 \
tar kernel-devel-$(uname -r) nano gpg git gcc-c++ gdb cmake \
perl libstdc++ libstdc++-static tcl expect dejagnu gcc-gnat \
binutils texinfo doxygen zlib zlib-devel glibc-devel autogen \
gettext gperf guile flex tex svn diffutils patch \
libuuid-devel gnulib-devel glibc-headers tar
sudo dnf install make automake autoconf gcc wget dkms bzip2 \
tar kernel-devel-$(uname -r) nano gpg git gcc-c++ gdb cmake \
perl libstdc++ libstdc++-static tcl expect dejagnu gcc-gnat \
fedora-gnat-project-common gprbuild binutils texinfo doxygen zlib \
zlib-devel glibc-devel autogen gettext gperf guile flex tex svn \
diffutils patch libuuid-devel gnulib-devel glibc-headers tar
sudo apt update && sudo apt install make automake \
autoconf gcc wget dkms bzip2 tar linux-headers-$(uname -r) \
nano gnupg git g++ gdb cmake perl libstdc++6 tcl expect \
dejagnu gnat binutils texinfo doxygen zlib1g zlib1g-dev \
libc6-dev autogen gettext gperf guile-2.0 flex texlive tar \
subversion diffutils patch uuid-dev gnulib glibc-source \
pkg-config software-properties-common equivs curl

If you are going to compile an older version of GCC (such as GCC 4), you may need gnat-5 rather than gnat for Ada support. More on GCC Ada support below.

You may need to install 32-bit libraries for some software, so do:

sudo dpkg --add-architecture i386
sudo apt update
sudo zypper install make automake autoconf gcc wget dkms bzip2 \
tar kernel-default-devel=$(uname -r | sed 's/-default.*//g') \
nano gpg git gcc-c++ gdb cmake perl libstdc++6 libstdc++-devel \
tcl expect dejagnu gcc-ada binutils texinfo doxygen libz1 \
zlib-devel glibc-devel autogen gettext-runtime gperf guile \
flex subversion diffutils patch libuuid-devel tar
sudo pacman -S make automake autoconf gcc wget dkms bzip2 \
tar linux-headers=$(uname -r | sed 's/-ARCH.*//g') nano gnupg \
git gdb cmake perl libstdc++5 tcl expect dejagnu gcc-ada \
binutils texinfo doxygen zlib glibc autogen gettext gperf \
guile flex svn diffutils patch libcrossguid tar

You may need the multilib repo depending on what you install, so do:

sudo nano /etc/pacman.conf

… and un-comment the multilib section. Then do:

sudo pacman -Sy

Since we are going to be downloading several archives from gnu.org we should verify their signatures. So download their GPG keyring and import it:

cd ~
wget http://ftp.gnu.org/gnu/gnu-keyring.gpg
gpg --import gnu-keyring.gpg
rm gnu-keyring.gpg

Lastly, since these tools will be installed to /usr/local, you should ensure the lib directory in there will be in your library path (many distributions do this automatically now, but it doesn’t hurt to make sure):

printf "/usr/local/lib\n/usr/local/lib64" | \
sudo tee /etc/ld.so.conf.d/usr-local.conf
sudo ldconfig

You should probably reboot at this point:

sudo reboot

Note On secure_path

Many distributions have the secure_path option set for sudo. This means your path variable will have no effect when running sudo, so the tools you compile will not be used by sudo commands. Normally, you could overcome this problem by adding the -E switch, but in many distributions the -E switch will not override secure_path. There are several ways to overcome this problem.

  1. Set the path environment every time you need it for sudo. Example: sudo env "PATH=$PATH" make. This is what most people recommend, but the downside is you have to try to remember when it is or isn’t necessary to set the path when running sudo. This is the only method that is guaranteed to work on all distros, so it is what I will focus on.
  2. Disable secure_path via visudo. This is not recommended for security reasons. It could break sudo.
  3. Edit the secure_path via visudo for every package you compile. This could also break sudo.

Make

Make sure you have the latest version of GNU Make installed. Some distributions ship with a different flavor (not GNU) of Make or an older version. To check:

make -v

The bare minimum you need for this tutorial is GNU Make 3.75, but you can check for the latest version via a GNU Make FTP mirror. There may be advantages to installing the latest version of GNU Make even if your distribution ships with 3.8x. So if your distribution has an older version do the following (change version number on first line as needed and copy/paste the rest into your SSH terminal).

TMPVER="4.2.1"
cd ~
wget ftpmirror.gnu.org/make/make-${TMPVER}.tar.gz
wget ftpmirror.gnu.org/make/make-${TMPVER}.tar.gz.sig
gpg --verify make-${TMPVER}.tar.gz.sig make-${TMPVER}.tar.gz

If you see "Good signature" in the results, then the file should be unaltered and you can continue. If you don’t, download again. Now configure and compile.

tar zxvf make-${TMPVER}.tar.gz
mkdir -v make-${TMPVER}/bld
cd make-${TMPVER}/bld

On Ubuntu and Debian, I had difficulty compiling Make 4.2.1. The issue has been reported as a bug and should be fixed in the next version. You can fix it yourself easily enough, but you must do it now, before running configure. So do:

sed -i \
"s/# if _GNU_GLOB_INTERFACE_VERSION == GLOB_INTERFACE_VERSION/# if _GNU_GLOB_INTERFACE_VERSION >= GLOB_INTERFACE_VERSION/g" \
../configure.ac

You should now be able to compile Make 4.2.1 successfully on all platforms.

../configure prefix=/usr/local
make && make check

Assuming the tests passed, you are ready to install. See the next two paragraphs for expected failures first.

If you have a recent version of Perl installed, during testing you may see an error like "Can’t locate test_driver.pl in @INC," which is a known bug and you can safely ignore it. A patch has already been submitted to the source tree and should be in the next version of Make or, if you are really concerned, you could apply the patch manually or even install the latest development version (which I don’t recommend for stability).

On CentOS I had three reported test failures, but after manually comparing the files, I realized they were identical. I am guessing the reported failures were due to some bug in the diff check or perhaps the check occurred before the test had completed. In any case, these three errors could be safely ignored.

Now install Gnu Make:

sudo make install
cd ~
sudo mv make-${TMPVER} /usr/local/src/
rm make-*
hash -r
make -v
sudo env "PATH=$PATH" make -v

The last two commands will verify that you are using the correct version, both as yourself and when running commands via sudo.


CMake

You will want a fairly new version of CMake, which some distributions do not have in their official repositories. First, check your current version.

cmake --version

Find the latest release version on the CMake download page. If your version is outdated, do the following (change version number on first line as needed and copy/paste the rest into your SSH terminal).

TMPVER="3.13.4"
cd ~
wget cmake.org/files/v$(echo $TMPVER | \
sed -e 's/\.[^\.]*$//')/cmake-${TMPVER}.tar.gz
wget cmake.org/files/v$(echo $TMPVER | \
sed -e 's/\.[^\.]*$//')/cmake-${TMPVER}-SHA-256.txt
diff <(sha256sum cmake-${TMPVER}.tar.gz | \
sed 's/ .*//') <(cat cmake-${TMPVER}-SHA-256.txt | \
sed -n '/cmake-'${TMPVER}'.tar.gz/p' | \
sed 's/\(.*\)cmake-'${TMPVER}'.tar.gz$/\1/')

That last command will ensure the checksum is valid. If the two values are not identical, download it again. Otherwise continue:

tar zxvf cmake-${TMPVER}.tar.gz
mkdir -v cmake-${TMPVER}/bld
cd cmake-${TMPVER}/bld
../configure --prefix=/usr/local
make && make test

Assuming all tests passed, you are ready to install:

sudo -E env "PATH=$PATH" make install
cd ~
sudo mv cmake-${TMPVER} /usr/local/src/
rm cmake-*
hash -r
cmake --version
sudo env "PATH=$PATH" cmake --version

The last two commands will verify that you are using the correct version, both as yourself and when running commands via sudo.


Perl

I recommend installing the latest version of Perl. Find the latest non-development version number on the CPAN website. Then check your installed version with the following:

perl -v

If you aren’t running a recent version, you can build it from source with the following commands (change version number on first line as needed and copy/paste the rest into your SSH terminal):

TMPVER="5.28.1"
cd ~
wget www.cpan.org/src/$(echo $TMPVER | \
sed 's/\..*$//').0/perl-${TMPVER}.tar.gz
wget www.cpan.org/src/$(echo $TMPVER | \
sed 's/\..*$//').0/perl-${TMPVER}.tar.gz.sha256.txt
diff <(sha256sum perl-${TMPVER}.tar.gz | sed 's/ .*//') \
<(cat perl-${TMPVER}.tar.gz.sha256.txt)

That last command will check the sha256 checksum of the archive against the contents of the text file to ensure the download is valid. You may see a message about there being no newline, but ignore that. So long as both values are identical, the file is good. If the download checks out, continue to compile Perl.

tar xzvf perl-${TMPVER}.tar.gz
cd perl-${TMPVER}
./Configure -des -Dprefix=/usr/local
make && make test

Assuming all tests passed, you can continue installing.

sudo -E env "PATH=$PATH" make install
cd ~
rm perl-*.tar*
sudo mv perl-${TMPVER} /usr/local/src/
hash -r
perl -v
sudo env "PATH=$PATH" perl -v

The last two commands will verify that you are using the correct version, both as yourself and when running commands via sudo.


GCC

Warning: this can be very time-consuming (as much as 10 hours in some cases). Please read these notes carefully to decide if you want to install a different version of GCC.

Check your installed version:

gcc -v

As of this writing, here are the versions installed on each distribution I tested:

CentOSFedoraUbuntuDebianopenSUSEArch Linux

4.8.5

8.2.1

7.3.0

6.3.0

7.3.1

8.2.1

As you can see, different distributions include very different versions of GCC, which is critical for compiling software. Check the GCC Releases page to see the latest releases in each branch.

Any of these versions of GCC will compile most software in this guide (see next paragraph). So it is up to you if you want to upgrade to the latest version. The advantage of upgrading is that you will have access to new C/C++ standards which may be required to compile some software (see this page for details). Using the method I cover here, you could always revert to your old version by either updating your path or pointing to a specific compiler. This process may vary slightly depending on what you are installing (example: ../configure CC=/usr/bin/cc).

THIS IS VERY IMPORTANT!!! If your system is running GCC 7+, some older versions of MariaDB may not compile (apparently no matter what flags you pass to it). This has been reported on Debian, but I encountered the same error on some other distributions. So you may want to install GCC 6 or older as a backup. More on this below and in the MySQL/MariaDB instructions, which we will get to in a bit.

Some distributions may have trouble compiling certain versions of GCC with certain languages (most notably Ada). You shouldn’t need these languages for any of the software in this guide, so leave them out of your enabled languages in your configure line below if you want to eliminate errors (I will cover this in detail for each tested distribution). If you run into problems, from your bld directory run the following and then re-run configure and everything after that:

rm -rf *

You may have issues installing certain versions of GCC, but if you have followed my instructions carefully you shouldn’t have any issues for the distributions I’m covering as of this writing.

Now, after reading all the warnings, if you want/need to install a different version of GCC, follow the instructions below carefully.

First of all, note that if you are installing an older version of GCC for compatibility, it is best to install to /opt rather than /usr/local. Since GCC 5/6 seemed best for compiling the software in this guide, I chose to install the following versions for each distribution:

CentOSFedoraUbuntuDebianopenSUSEArch Linux

6.5.0 to /usr/local.

6.5.0 (without Ada support) to /opt/gcc6.

Important: Ubuntu 18.04 (the current LTS release) has a lot of problems compiling GCC. Many people have reported this issue. There’s some evidence this has to do with Autoconf 2.69, but Debian has the same version of Autoconf and didn’t have any issues compiling GCC 6. If you need to install an older version of MariaDB that GCC 7 can’t compile, there is a simple fix:

sudo apt install gcc-6

You will need to pass gcc-6 to your configure options when necessary in order to bypass GCC 7. More on this later. Alternately if you just want to use GCC 6 as your default, you could do the following (and could always use rm to remove the links from /usr/local/bin):

sudo ln -sv /usr/bin/gcc-6 /usr/local/bin/gcc
sudo ln -sv /usr/bin/cpp-6 /usr/local/bin/cpp
hash -r

6.5.0 to /usr/local. Technically this wasn’t necessary since the included 6.3 seemed to work fine, so you could save time by just sticking with 6.3.

6.5.0 to /opt/gcc6.

6.5.0 (without Ada support) to /opt/gcc6.

Here are the instructions for installing the current latest release in every branch from 4-8. Replace the version in the first line with whatever version you wish to install, replace the path in the second line with the location you wish to install to (see examples above), then copy/paste the rest into your SSH terminal.

GCC 4GCC 5GCC 6GCC 7GCC 8
TMPVER="4.9.4"
TMPPATH="/usr/local"
cd ~
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
tar xvjf gmp-4.3.2.tar.bz2
tar xvjf mpfr-2.4.2.tar.bz2
tar zxvf mpc-0.8.1.tar.gz
wget ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz
wget ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz.sig
gpg --verify gcc-${TMPVER}.tar.gz.sig gcc-${TMPVER}.tar.gz

If you see "Good signature" in the results, then the file should be unaltered and you can continue. If you don’t, download again. Now create your source tree as recommended by the GCC team.

mkdir -vp gcc-${TMPVER}/bld
tar zxvf gcc-${TMPVER}.tar.gz -C gcc-${TMPVER}
mv gcc-${TMPVER}/gcc-${TMPVER} gcc-${TMPVER}/src
mv gmp-4.3.2 gcc-${TMPVER}/src/gmp
mv mpfr-2.4.2 gcc-${TMPVER}/src/mpfr
mv mpc-0.8.1 gcc-${TMPVER}/src/mpc
cd gcc-${TMPVER}/bld
TMPVER="5.5.0"
TMPPATH="/usr/local"
cd ~
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
tar xvjf gmp-6.1.0.tar.bz2
tar xvjf mpfr-3.1.4.tar.bz2
tar zxvf mpc-1.0.3.tar.gz
wget ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz
wget ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz.sig
gpg --verify gcc-${TMPVER}.tar.gz.sig gcc-${TMPVER}.tar.gz

If you see "Good signature" in the results, then the file should be unaltered and you can continue. If you don’t, download again. Now create your source tree as recommended by the GCC team.

mkdir -vp gcc-${TMPVER}/bld
tar zxvf gcc-${TMPVER}.tar.gz -C gcc-${TMPVER}
mv gcc-${TMPVER}/gcc-${TMPVER} gcc-${TMPVER}/src
mv gmp-6.1.0 gcc-${TMPVER}/src/gmp
mv mpfr-3.1.4 gcc-${TMPVER}/src/mpfr
mv mpc-1.0.3 gcc-${TMPVER}/src/mpc
cd gcc-${TMPVER}/bld
TMPVER="6.5.0"
TMPPATH="/usr/local"
cd ~
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
tar xvjf gmp-6.1.0.tar.bz2
tar xvjf mpfr-3.1.4.tar.bz2
tar zxvf mpc-1.0.3.tar.gz
tar xvjf isl-0.16.1.tar.bz2
wget ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz
wget ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz.sig
gpg --verify gcc-${TMPVER}.tar.gz.sig gcc-${TMPVER}.tar.gz

If you see "Good signature" in the results, then the file should be unaltered and you can continue. If you don’t, download again. Now create your source tree as recommended by the GCC team.

mkdir -vp gcc-${TMPVER}/bld
tar zxvf gcc-${TMPVER}.tar.gz -C gcc-${TMPVER}
mv gcc-${TMPVER}/gcc-${TMPVER} gcc-${TMPVER}/src
mv gmp-6.1.0 gcc-${TMPVER}/src/gmp
mv mpfr-3.1.4 gcc-${TMPVER}/src/mpfr
mv mpc-1.0.3 gcc-${TMPVER}/src/mpc
mv isl-0.16.1 gcc-${TMPVER}/src/isl
cd gcc-${TMPVER}/bld
TMPVER="7.4.0"
TMPPATH="/usr/local"
cd ~
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
tar xvjf gmp-6.1.0.tar.bz2
tar xvjf mpfr-3.1.4.tar.bz2
tar zxvf mpc-1.0.3.tar.gz
tar xvjf isl-0.18.tar.bz2
wget ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz
wget ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz.sig
gpg --verify gcc-${TMPVER}.tar.gz.sig gcc-${TMPVER}.tar.gz

If you see "Good signature" in the results, then the file should be unaltered and you can continue. If you don’t, download again. Now create your source tree as recommended by the GCC team.

mkdir -vp gcc-${TMPVER}/bld
tar zxvf gcc-${TMPVER}.tar.gz -C gcc-${TMPVER}
mv gcc-${TMPVER}/gcc-${TMPVER} gcc-${TMPVER}/src
mv gmp-6.1.0 gcc-${TMPVER}/src/gmp
mv mpfr-3.1.4 gcc-${TMPVER}/src/mpfr
mv mpc-1.0.3 gcc-${TMPVER}/src/mpc
mv isl-0.18 gcc-${TMPVER}/src/isl
cd gcc-${TMPVER}/bld
TMPVER="8.2.0"
TMPPATH="/usr/local"
cd ~
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
tar xvjf gmp-6.1.0.tar.bz2
tar xvjf mpfr-3.1.4.tar.bz2
tar zxvf mpc-1.0.3.tar.gz
tar xvjf isl-0.18.tar.bz2
wget ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz
wget ftpmirror.gnu.org/gcc/gcc-${TMPVER}/gcc-${TMPVER}.tar.gz.sig
gpg --verify gcc-${TMPVER}.tar.gz.sig gcc-${TMPVER}.tar.gz

If you see "Good signature" in the results, then the file should be unaltered and you can continue. If you don’t, download again. Now create your source tree as recommended by the GCC team.

mkdir -vp gcc-${TMPVER}/bld
tar zxvf gcc-${TMPVER}.tar.gz -C gcc-${TMPVER}
mv gcc-${TMPVER}/gcc-${TMPVER} gcc-${TMPVER}/src
mv gmp-6.1.0 gcc-${TMPVER}/src/gmp
mv mpfr-3.1.4 gcc-${TMPVER}/src/mpfr
mv mpc-1.0.3 gcc-${TMPVER}/src/mpc
mv isl-0.18 gcc-${TMPVER}/src/isl
cd gcc-${TMPVER}/bld

Following is the configuration procedure I used.

If you have trouble running configure for Ada, you can probably safely remove it from the list and just use GNAT to compile Ada code instead. It isn’t necessary for anything in this guide. I am just including all languages in case you want to compile something else on this machine in the future.

../src/configure -v --prefix=${TMPPATH} \
--disable-multilib \
--enable-languages=c,ada,c++,fortran,go,objc,obj-c++,lto

Compile and check. The check process may appear to hang at certain points. I ran into a lot of timeouts testing GCC 6 on the latest version of Fedora especially. This could have been due to inadequate resources on the VM (a common problem), so if time is of the essence and you are just installing GCC 6 for the rare case where you need it, you may want to skip the && make -k check portion of the commands below.

SED=sed
make -j$(nproc) && ulimit -s 32768 && make -k check
../src/contrib/test_summary | grep -A7 Summ

Look over the summary of all tests. If you just want a summary of the unexpected failures, try this:

../src/contrib/test_summary | grep -B4 -A4 unexpected

If you see a lot of unexpected failures, then something may have gone wrong (some unexpected failures are normal depending on your platform and configure options). You can run the last command again (everything before the pipe) to find the details, then look up the errors if you’re concerned. If you have hundreds or thousands of unexpected failures, you’re probably missing some prerequisite. Otherwise you can usually ignore it even if there are a few dozen errors (especially on a slow system or virtual machine, this is normal).

Now, finally, install:

sudo -E env "PATH=$PATH" make install
sudo ldconfig
hash -r
gcc -v
sudo env "PATH=$PATH" gcc -v
${TMPPATH}/bin/gcc -v
sudo env "PATH=$PATH" ${TMPPATH}/bin/gcc -v

The last four commands will verify that you are using the correct version, both as yourself and when running commands via sudo. If you did not install to /usr/local then the first two will show your system-provided version and the last two will show the version you just installed. If you installed to /usr/local then all four should show this new version.

Create some symlinks next (ignore errors; I’m covering various distributions).

GCC 4GCC 5GCC 6GCC 7GCC 8
sudo ln -sv ../bin/cpp ${TMPPATH}/lib
sudo ln -sv gcc ${TMPPATH}/bin/cc
sudo install -v -dm755 ${TMPPATH}/lib/bfd-plugins
sudo ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/${TMPVER}/liblto_plugin.so \
${TMPPATH}/lib/bfd-plugins/
sudo ln -sv ${TMPPATH}/lib64/libstdc++.so.6.0.20-gdb.py \
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.20-gdb.py
sudo ln -sv ${TMPPATH}/lib64/libstdc++.so.6.0.20-gdb.py \
/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.20-gdb.py
sudo ln -sv ../bin/cpp ${TMPPATH}/lib
sudo ln -sv gcc ${TMPPATH}/bin/cc
sudo install -v -dm755 ${TMPPATH}/lib/bfd-plugins
sudo ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/${TMPVER}/liblto_plugin.so \
${TMPPATH}/lib/bfd-plugins/
sudo ln -sv ${TMPPATH}/lib64/libstdc++.so.6.0.21-gdb.py \
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.21-gdb.py
sudo ln -sv ${TMPPATH}/lib64/libstdc++.so.6.0.21-gdb.py \
/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.21-gdb.py
sudo ln -sv ../bin/cpp ${TMPPATH}/lib
sudo ln -sv gcc ${TMPPATH}/bin/cc
sudo install -v -dm755 ${TMPPATH}/lib/bfd-plugins
sudo ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/${TMPVER}/liblto_plugin.so \
${TMPPATH}/lib/bfd-plugins/
sudo ln -sv ${TMPPATH}/lib64/libstdc++.so.6.0.22-gdb.py \
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.22-gdb.py
sudo ln -sv ${TMPPATH}/lib64/libstdc++.so.6.0.22-gdb.py \
/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.22-gdb.py
sudo ln -sv ../bin/cpp ${TMPPATH}/lib
sudo ln -sv gcc ${TMPPATH}/bin/cc
sudo install -v -dm755 ${TMPPATH}/lib/bfd-plugins
sudo ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/${TMPVER}/liblto_plugin.so \
${TMPPATH}/lib/bfd-plugins/
sudo ln -sv ${TMPPATH}/lib64/libstdc++.so.6.0.24-gdb.py \
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.24-gdb.py
sudo ln -sv ${TMPPATH}/lib64/libstdc++.so.6.0.24-gdb.py \
/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.24-gdb.py
sudo ln -sv ../bin/cpp ${TMPPATH}/lib
sudo ln -sv gcc ${TMPPATH}/bin/cc
sudo install -v -dm755 ${TMPPATH}/lib/bfd-plugins
sudo ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/${TMPVER}/liblto_plugin.so \
${TMPPATH}/lib/bfd-plugins/
sudo ln -sv ${TMPPATH}/lib64/libstdc++.so.6.0.25-gdb.py \
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.25-gdb.py
sudo ln -sv ${TMPPATH}/lib64/libstdc++.so.6.0.25-gdb.py \
/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.25-gdb.py

Check that cc is pointing to the new version with:

${TMPPATH}/bin/cc -v

Test the installation with:

cd ~
echo 'int main(){}' > dummy.c
${TMPPATH}/bin/cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'

That last command should output something like:

[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]

Now do:

grep -o '/lib.*/crt[1in].*succeeded' dummy.log

Which should output (note that .. may be replaced by something like x86_64-linux-gnu or something else depending on your distribution):

/lib/../lib64/crt1.o succeeded
/lib/../lib64/crti.o succeeded
/lib/../lib64/crtn.o succeeded

And now:

grep -B5 '^ /usr/include' dummy.log

Which should return (allowing for differences in architecture and GCC version number) the following. The important thing is that the include path of your newly-installed version appears first.

#include <...> search starts here:
 /opt/gcc6/lib/gcc/x86_64-pc-linux-gnu/6.5.0/include
 /usr/local/include
 /opt/gcc6/include
 /opt/gcc6/lib/gcc/x86_64-pc-linux-gnu/6.5.0/include-fixed
 /usr/include

Do some housecleaning:

sudo mv gcc-${TMPVER} /usr/local/src/
rm -v a.out dummy.c dummy.log gmp-*.tar* mpfr-*.tar* \
mpc-*.tar* isl-*.tar* gcc-*.tar*

Final Notes

It is a really good idea to reboot your system now:

sudo reboot

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.