Next Previous Contents

7. Installing the GNU C and C++ compilers

You need to restart your system back into the normal Linux system to compile the gcc compiler. Before you reboot, unmount the partitions you mounted (that contained the glibc sources) and mount the LFS root partition read only by running mount -o remount,ro / /

If you have used a previous version of this HOWTO to install a LFS system and you wish to update your LFS system conforming the changes made in this version, you first need to remove the existing files regarding the previously installed compilers before continuing with this section.

This HOWTO used to install the C++ compiler from source, but that has been changed and is an exception. The C++ compiler is installed using pre-compiled binaries. The reason is that I have not been able to find the sources for the C++ compiler version that I prefer to use. So until then we'll use pre-compiled binaries.

We also will link the C compiler statically. Although Glibc is installed on our LFS system, we still are compiling the compiler on our normal Linux system. The normal Linux system may contain a different version of Glibc and the compiler will be linked against that version. Therefore we will link the compiler statically and later on when all statically linked software is being re-installed we also will re-install the compiler. This procedure is not necessary if both your normal Linux system and the LFS system use the same Library version, but since I don't know that we will do it this way. This ensures this document is usable on every Linux system, no matter what version of libraries they use.

7.1 Making two small test programs

We'll create a little C and a little C++ program which we will use after the installations to determine if the compilers can find the necessary files in order to successfully compile a program.

// Begin test.c
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
// End test.c
 

// Begin test2.cpp
#include <iostream.h>
int main() {
cout << "Hello World!" << endl;
return 0;
}
// End test2.cpp
 

7.2 Installing GCC 2.7.2.3

make LANGUAGES=c
make stage1 
make CC="stage1/xgcc -Bstage1/" CFLAGS="-g -O2 -static" LANGUAGES=c
make stage2
make CC="stage2/xgcc -Bstage2/" CFLAGS="-g -O2 --static" LANGUAGES=c
make compare
 

7.3 Installing the g++_2.91.66-0slink2.deb package

Note that this g++ compiler is already pre-compiled and linked against glibc 2.0.7. Therefore there is no need to re-install this package in a later stage.

7.4 Creating necessary symlinks

Replace <host> with the directory where the gcc-2.7.2.3 files were installed (i686-unknown-linux in my case).

7.5 Testing the compilers

We will compile two small programs which we will use to test if the compilers compile. Note that this is by no means an exhaustive test. It's just a little test to see if the compiler can find the necessary files in order to compile a basic program.


Next Previous Contents