Installing GCC on the normal system if necessary

Installation of GCC on the normal system if necessary

In order to compile Glibc-2.1.3 later on you need to have gcc-2.95.2 installed. Although any GCC version above 2.8 would do, 2.95.2 is the highly recommended version to use. egcs-2.91.x is also known to work. If you don't have gcc-2.95.x or egcs-2.91.x you need to install gcc-2.95.2 on your normal sytem before you can compile Glibc later in this chapter.

To find out which compiler version your systems has, run the following command:



gcc --version

If you normal Linux system does not have gcc-2.95.x or egcs-2.91.x installed you need to install it now. We won't replace the current compiler on your system, but instead we will install gcc in a separate directory (/usr/local/gcc2952). This way no binaries or header files will be replaced.

After you unpacked the gcc-2.95.2 archive don't enter the newly created gcc-2.95.2 directory but stay in the $LFS/usr/src directory. Install GCC by running the following commands:



mkdir $LFS/usr/src/gcc-build &&
cd $LFS/usr/src/gcc-build &&
../gcc-2.95.2/configure \
   --prefix=/usr/local/gcc2952 \
   --with-local-prefix=/usr/local/gcc2952 \
   --with-gxx-include-dir=/usr/local/gcc2952/include/g++ \
   --enable-shared --enable-languages=c,c++ &&
make bootstrap &&
make install

Command explanations

--with-local-prefix: GCC installs a number of files in /usr/local even when --prefix is set to something else. We don't want that to happen in this case so that's why we use the --with-local-prefix option to change that path.

--with-gxx-include-dir: GCC installs the C++ header files in /usr/include/g++ by default. Again, in this case we don't want that to happen, we want this GCC version to be installed completely under /usr/local/gcc2952.

make bootstrap: Compile GCC by bootstrapping it. Here that means the compiler will be built three times in total. First it is compiled with your system's default compiler (which will usually be a gcc or egcs compiler). This is stage 1 compiler. Then GCC will re-compile itself but instead of using your system's compiler it will use itself to compile itself again. This is the stage 2 compiler. Then it will compile itself a second time with the stage 2 compiler and compares the second and the third build to see if they are identical. If so, the compilation was a success.

Contents

The GCC package contains compilers, preprocessors and the GNU C++ Library.

Description

Compiler

A compiler translates source code in text format to a format that a computer understands. After a source code file is compiled into an object file, a linker will create an executable file from one or more of these compiler generated object files.

Pre-processor

A pre-processor pre-processes a source file, such as including the contents of header files into the source file. You generally don't do this yourself to save yourself a lot of time. You just insert a line like #include <filename>. The pre-processor file insert the contents of that file into the source file. That's one of the things a pre-processor does.

C++ Library

The C++ library is used by C++ programs. The C++ library contains functions that are frequently used in C++ programs. This way the programmer doesn't have to write certain functions (such as writing a string of text to the screen) from scratch every time he creates a program.