Building the Lastest Compilers and Tools

by Walt Stoneburner
"Installing a new compiler; now that sounds hard..."

Installing the latest compiler collections and utilities isn't as hard as one might think. Here's the quick cheat sheet to do just that for those that don't want to read the manual.

Go to GNU's GCC Homepage and download from a mirror site the latest release.

Start in a work area with lots of space and snag the required source files from a mirror.
$ cd /tmp
/tmp$ ncftp ftp://ftp.gnu.org/
ncftp /gnu/gcc > cd gcc
ncftp /gnu/gcc/gcc > ls
Find the latest compiler directory
ncftp /gnu/gcc/gcc > cd gcc-3.4.1
ncftp /gnu/gcc/gcc/gcc-3.4.1 > ls -l
And download the latest compiler. This will be the largest file with no special prefixes.
ncftp /gnu/gcc/gcc/gcc-3.4.1 > binary
ncftp /gnu/gcc/gcc/gcc-3.4.1 > get gcc-3.4.1.tar.gz

You will also need the latest binutils package.
ncftp /gnu/gcc/gcc/gcc-3.4.1 > cd ../..
(If not there, then try another mirror.)
ncftp /gnu/gcc > cd binutils/
ncftp /gnu/gcc/binutils > ls -l
ncftp /gnu/gcc/binutils > get binutils-2.14.tar.gz
ncftp /gnu/gcc/binutils > quit

Extract, build, and install the binutils -- this creates the compiler, linker, and other utilities needed to make the system.
/tmp$ tar zxvf binutils-2.14.tar.gz
/tmp$ cd binutils-2.14
/tmp/binutils-2.14$ ./configure
/tmp/binutils-2.14$ make
/tmp/binutils-2.14# make install

    If you ever happen to get an error that looks like:
    Unrecognized .section attribute: want a,w,x
    then what you want to do is go into the Makefile and remove the C compiler's optimization switches, which are usually -O2. Then try make again.
Make sure the latest dynamic libraries are now available.
You'll want to check /etc/ld.so.conf and make sure that the line:
 /usr/local/lib
is in it. If not, use your favorite text editor like pico, vi, vim, or emacs to add it.

Then, issue the following command as root to bring the linker up to date with the new libraries (your location of ldconfig may vary):
/tmp/binutils-2.14# /sbin/ldconfig

Now, it's time to make the compiler:
$ cd /tmp
/tmp$ tar zxvf gcc-3.4.1.tar.gz
/tmp$ cd gcc-3.4.1
/tmp/gcc-3.4.1$ mkdir objdir
/tmp/gcc-3.4.1$ cd objdir
/tmp/gcc-3.4.1/objdir$ ../configure
This next step will cause a three-phase compilation.
/tmp/gcc-3.4.1/objdir$ make bootstrap

    Important Note for GCC v3.1: Including and using <fstream> may result in an error that looks like this:
      In file included from /usr/local/include/g++-v3/fstream:48,
                       from read.cpp:2:
      /usr/local/include/g++-v3/bits/basic_file.h:52: parse error before `{' token
      /usr/local/include/g++-v3/bits/basic_file.h:57: virtual outside class 
         declaration
      /usr/local/include/g++-v3/bits/basic_file.h:57: function `int std::overflow(int 
         = -1)' is initialized like a variable
      
    To resolve the problem before installing at the next step by getting rid of your existing installation's include files:
    $ rm -rf /usr/local/include/g++-v3

    Details are at http://gcc.gnu.org/ml/gcc/2002-06/msg01537.html, and you want to make sure you check out the thread responses.

Now install the compiler:
/tmp/gcc-3.4.1/objdir# make install

Once again, bring your linker up to date with the libraries.

Check /etc/ld.so.conf and make sure that the line:
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.1
is in it. If not, add it. These directories are told to you in the installation messages; look for blocks of text that talk about where Libraries have been installed.

Additionally, make sure that /usr/local/lib is before /usr/lib in /etc/ld.so.conf, this way if you have duplicate libraries, your more recent versions (in /usr/local/lib) should be seen first. TIP: to get rid of your duplicate libraries in /usr/lib this command may be of use:

    # cd /usr/local/lib; for f in * ; do if [ -f /usr/lib/$f ] ;
      then ls -l $f /usr/lib/$f ; rm -v /usr/lib/$f ; echo "." ; fi; done
/tmp# /sbin/ldconfig

You now have the latest assembler, linker, C, C++, Object C, Chill, Fortran, and Java compilers, as well as the latest libraries for those languages.

SlingCode Search Results About     Articles     Links     Search Tips  
SEARCH: