Blog
Alternative GCC compilers on Ubuntu Intrepid and Jaunty

While trying to compile a suitably recent Xen Dom0 Kernel for use on Ubuntu Intrepid and Jaunty instalations, I found that that derfault installed GCC compiler version 4.3 wasn actually suitable. I was getting an error at link time:

 


Research on the internet revealed that the cause of this was the fact that the kernel would not compile using the installed GCC. Infact people where advising to build the kernel on a machine otwith an older version of Ubuntu installed. That wasn really practical for me, so I had a look around to see if there was a possibility to install and older c compiler on Ubuntu without causing a lot of other problems, and as it turned out its quite painless. You can even use the alternatives software to switch between them in much the same way you can java. You can do this as follows.

Firstly open a root shell like this:

sudo su -

Then install the older GCC like this:

apt-get install gcc-4.2
apt-get install g++-4.2

Then configure alternatives like this:

 

update-alternatives --remove-all gcc
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.2 42
--slave /usr/bin/g++ g++ /usr/bin/g++-4.2
--slave /usr/bin/gcov gcov /usr/bin/gcov-4.2
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 43
--slave /usr/bin/g++ g++ /usr/bin/g++-4.3
--slave /usr/bin/gcov gcov /usr/bin/gcov-4.3
 
And then choose which GCC you want to use like this:
update-alternatives --config gcc
 
Then you can 'exit' the sudo root shell.
 
Now you can use either GCC.
Posted By: admin on Apr 28, 2009 02:22PM Category:Ubuntu Add Comment

I have a 32 bit machine and I am running Ubuntu 9.10 on it. I have the latest gcc compiler. The problem that I am facing is that I have a library developed in 2002. The code is correct for sure but when I try to built it, it gives me errors like iostream.h cannot be found, error: fstream.h: No such file or directory etc etc.

Can these errors be solved if solved I install gcc 3.0 ? If yes how to install it.

Posted By: pratik agarwal on Feb 08, 2010 03:11PM

You should install the libstdc++-dev package.

Posted By: Walter on Nov 05, 2010 08:31AM