Home > Computer Science, How To > Compiling GCC

Compiling GCC

I have recently been working on GCC for a kind of research and first problem I encountered was to compile GCC from its source. Having compiled it, now it seems pretty straightforward. However I need to admit that it is really hard to find a complete guide to compile GCC especially for beginners who doesn’t compiled such a huge source before.

I know that it cannot be considered as a guide, but “official” prerequisites of GCC compilation are listed in http://gcc.gnu.org/install/prerequisites.html. Most of these are already come installed in most systems.

First of all you need to compile couple of libraries in order to be able to compile GCC. Before my compilation experience, I need to note my configuration’s version, you also need to be aware that those libraries are also dependent on each other and you need to install compatible versions.

  • Ubuntu Version : 11.10
  • Stable GCC Version : 4.6.1
  • Installed GCC Version : 4.7.0 (Still seems experimental)

Five libraries that I had to install before GCC are like below.

  • gmp : GNU Multiple Precision. In the website of the gmp it seems that the current version is 5.0.4. I have installed 5.0.2.
  • mpfr : Seems like it is used for high precision floating-point arithmetic with correct rounding emphasized. I have installed version 3.1.0.
  • mpc : Like mpfr, but as far as I understand it deals with complex number arithmetic. I have installed version 0.9.
  • ppl : Parma Polyhedra Library, used for loop optimizations as far as I concern. I have installed version 0.11.2.
  • cloog-to-ppl : As I understand, able to find code segments that are to be represented by polyhedra. I have installed 0.15.11.

For installation of all these libraries -and also GCC itself- simple compilation commands are enough.

Go to the libraries’ root folder and

./configure
make
make install

That would do the job. As it can be seen in http://gcc.gnu.org/wiki/Graphite_Build, you can specify libraries’ installation folders. Otherwise it will go directly to your default installation path (most probably /usr/local/). Important thing to note that if you want to specify some other path(specifically a path that is not in your library search path), you need to be careful when you install consequent libraries.

For example: mpc depends on gmp. If you have installed gmp in another directory, You need to configure mpc accordingly.

./configure –with-gmp=YOUR_PATH_HERE
make
make install

I am not sure about all of the dependencies among these libraries, but if you compile them in the order given above, that wouldn’t be a problem. You can also go to their websites and look for their dependencies.

Having installed all of these libraries you can go to GCC source folder and compile your new GCC. One last thing to note that you should add a prefix or suffix to your executable so that your stable GCC remains intact.

./configure –program-prefix=my
make
make install

After installation you can compile source with your new GCC:

mygcc source.c


Advertisements
Categories: Computer Science, How To
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: