Technology
 

How to install GCC 4.3.0

From Cygwin Wiki

The GCC version in Cygwin distribution is 3.4.4-3, which is very outdated. This article describes how to upgrade it to 4.3.0 (or any other version of GCC).

Contents

[edit] Disclaimer

I wrote this text in my spare time. It is provided without any guarantees whatsoever.

[edit] Warning

After you install GCC 4.3, some things like exception handling or shared code may not work, see here, so install on your own risk. However, new gcc will be installed under /usr/local/bin; you'll still have old GCC under /usr/bin or /bin.

[edit] Prerequisities

Check that you have following packages under Cygwin

  • bash
  • binutils
  • bzip2 (version 1.0.2 or later)
  • gcc-core (or any other C compilier)
  • gcc-ada (any version; needed only if you want to install Ada compilier)
  • gzip (version 1.2.4 or later)
  • m4
  • make (version 3.79.1 or later)
  • either gcc-java (only jar command is needed) or zip and unzip (needed ony if you want to install Java)

You may check their existence and version numbers with the following command:

   cygcheck -c bash binutils bzip2 gcc-core gcc-java  gzip m4 make unzip zip

If something is missing or outdated, download it from the Cygwin site (http://cygwin.com/setup.exe). You can find:

  • binutils, gcc-core, gcc-ada, gcc-java, and make in the Devel section,
  • m4 in the Interpreters section
  • bash and gzip in the Base section,
  • zip and unzip in the Archive section
  • bzip2 in the Utils section

[edit] LD_LIBRARY_PATH

Your enviromnment variable LD_LIBRARY_PATH should exist and contain /usr/local/lib

You may check it with

   printenv LD_LIBRARY_PATH

If it doesn't exist, run for bash

   export LD_LIBRARY_PATH=/usr/local/lib

Or for csh/tcsh

   setenv LD_LIBRARY_PATH /usr/local/lib

This command also should be included into your .bash_profile or .profile (if you use bash) or .cshrc or .tcshrc (if you use csh/tcsh).

[edit] Before installing anything

The make utility has -j option for parallel installation. Running it as

   make -j 2 ...

would significantly speed up the installation, especially if you have dual core processor. You may even specify -j more than 2 and get even faster installation (because CPU and CPU cores are idle during input-output, etc.).

If you have Spybot S&D, its TeaTimer.exe will slow down the installation. You may want to disable it or kill it in Task Manager for the time of installation.

[edit] How to install any package manually

In order to install any package, do the following:

  1. Download it to any directory (I use the directory /usr/local/contrib which I created for this purpose)
  2. Open it with tar -xvf command (i. e. tar -xvf gmp-4.2.2.tar.gz)
  3. Go to the directory where it was unpacked (i. e. cd gmp-4.2.2)
  4. Read the file called INSTALLATION.
  5. Run ./configure (this will check the configuration of your system)
  6. Run make (this will build everything)
  7. Run make check (optional but recommended; this will check that everything is correct)
  8. Run make install (this will install all the relevant files to the relevant directories)
  9. Run make clean (optional; this will erase intermediate files)


[edit] Installing GCC

  • Go to http://gmplib.org/, download and manually install GMP. GMP is library for arbitrary precision arithmetics. It is required for MFPR. Official GMP is old and does not work.
  • Go to http://mpfr.org/, download and manually install MPFR. It is a library for arbitrary precision floating-number arithmetics which produces exactly same results for any CPU or operating systems. It is required for GCC.
  • Go to http://gcc.gnu.org/mirrors.html, select a mirror (some don't work, so you possibly try 2-3 mirrors until you find a working one), and download gcc-4.3.0.tar.bz2. The file length should be 57932K (if you select a different version of GCC, the instructions are the same, but of course, expect a different file length)
  • Unpack the source:
 $ tar xjf gcc-*.tar.bz2
  • Unlike many packages, you must not build GCC from the source directory. Instead, create a build directory alongside the source directory, and do the configure and make steps there:
 $ mkdir build
 $ cd build
 $ ../gcc-*/configure --enable-languages=c,c++
 $ make
 $ make install
  • The "--enable-languages" option specifies here to build gcc (the C compiler) and g++ (the C++ compiler). GCC actually includes many languages. If you leave out this option you'll build all of them, which could easily take 4 hours or so. See the GCC configuration page for details.
  • If you'll need to install multiple versions of GCC, you'll want to use the --prefix argument so they don't all end up in /usr/local. See the configure --help output for details.
  • The "make" step of this installation can still take a long time. To speed it, you may want to replace make with make -j 2 or make -j 3, especially for computers with multi-core CPUs.
  • You cannot perform the make check step; run make install immediately after make. This is because make check requires autogen which requires libguile which requires libtool. If you would try to install libtool, guile, and autogen, then you will see that guile (v 1.8.4) has some problems (fails 2 tests of 64) and autogen (v 5.9.4) does not work (fails 18 tests of 20).

[edit] After GCC is installed

If you want to use new GCC by default, make sure that your PATH contains /usr/local/bin before /bin and /usr/bin.

You may check it with

printenv PATH

This is because new GCC will be installed under /usr/local/bin, while /bin/gcc and /usr/bin/gcc will still point to old GCC (3.4.4).