5.11. Installing GCC-2.95.3

Estimated build time:           22 minutes
Estimated required disk space:  168 MB

5.11.1. Installation of GCC

This package is known to behave badly when you have changed its default optimization flags (including the -march and -mcpu options). GCC is best left alone, so we recommend you unsetting CFLAGS, CXXFLAGS and other such variables/settings that would change the default optimization that it comes with.

Install GCC by running the following commands:

patch -Np1 -i ../gcc-2.95.3-2.patch &&
mkdir ../gcc-build &&
cd ../gcc-build &&
../gcc-2.95.3/configure --prefix=/usr --enable-languages=c,c++ \
   --disable-nls --disable-shared --enable-threads=posix &&
make BOOT_LDFLAGS=-static bootstrap &&
make prefix=$LFS/usr install &&
cd $LFS/lib &&
ln -sf ../usr/bin/cpp &&
cd $LFS/usr/lib &&
ln -sf ../bin/cpp &&
cd $LFS/usr/bin &&
ln -sf gcc cc &&
rmdir $LFS/usr/*-gnu/include &&
rmdir $LFS/usr/*-gnu

5.11.2. Command explanations

patch -Np1 -i ../gcc-2.95.3-2.patch: This new patch deals with incorrect handling of weak symbols, the over-optimization of calls to those weak symbols, an atexit issue and the __dso_handle symbol required for atexit's proper function.

make BOOT_LDFLAGS=-static: This is the equivalent to make LDFLAGS=-static as we use with other packages to compile them statically.

--prefix=/usr: This is NOT a typo. GCC hard codes some paths while compiling and so we need to pass /usr as the prefix during ./configure. We pass the real install prefix during the make install command later.

--enable-languages=c,c++: This only builds the C and C++ compilers and not the other available compilers as they are, on the average, not often used. If those other compilers are needed, the --enable-languages parameter can be omitted.

--enable-threads=posix: This enables C++ exception handling for multithreaded code.

ln -sf ../usr/bin/cpp: This creates the $LFS/lib/cpp symlink. Some packages explicitly try to find cpp in /lib.

ln -sf ../bin/cpp: This creates the $LFS/usr/lib/cpp symlink as there are packages that expect cpp to be in /usr/lib.

rmdir $LFS/usr/*-gnu/include and rmdir $LFS/usr/*-gnu: These directories are created as empty directories by GCC and serve absolutely no purpose whatsoever. It's related to cross-compilers but that doesn't apply to us and it's considered a bug in GCC that you can't turn that off, especially since they end up being empty directories. So we remove them manually.

5.11.3. Contents of gcc-2.95.3

5.11.4. Dependencies

GCC-2.95.3 needs the following to be installed:


bash: sh
binutils: ar, as, ld, nm, ranlib
diffutils: cmp
fileutils: chmod, cp, ln, ls, mkdir, mv, rm, touch
find: find
gcc: cc, cc1, collect2, cpp0, gcc
grep: egrep, grep
make: make
patch: patch
sed: sed
sh-utils: basename, dirname, echo, expr, hostname, sleep, true, uname
tar: tar
texinfo: install-info, makeinfo
textutils: cat, tail, tr