views:

812

answers:

2

Hi,

I am using ubuntu 9.10 and it comes with gcc 4.4. How can I install gcc 4.5 without screwing up my gcc 4.4. environment. I just need gcc 4.5 to compile 1 application.

Thank you.

A: 

The easiest way is to install into a private prefix:

configure --prefix=/some/private/prefix   ...

In a private prefix, there is 0 chance you'll overwrite an existing file. You'll then need to add the prefix to your path.

A second option is to give the new binaries a suffix and to use version specific runtime libraries:

configure --program-suffix=-4.5.0 --enable-version-specific-runtime-libs

although I can't promise some other file won't be modified.

R Samuel Klatchko
How on earth does this work?
Shakedown
It works by having this packaged installed in a new directory. Since all files are installed within the new directory, there is no chance of conflict.It does require you to add the new directory to your path when you want to use the new binary (`PATH=/some/private/prefix/bin:${PATH}`).
R Samuel Klatchko
I assume you suggest me to download and compile gcc 4.5 myself. But my concern is it may need another set of dependencies?
michael
@michael - yes, gcc has a few dependencies (see http://gcc.gnu.org/install/prerequisites.html). The ones you are most likely to need are GMP, MPFR and MPC. Install all of them into a single private prefix.
R Samuel Klatchko
+1  A: 

My preferred method is to have a deb-src entry in /etc/apt/sources.list as e.g.

# Debian sources
deb-src http://ftp.us.debian.org/debian/ unstable main contrib non-free

I can then do apt-get source foo and fetch the appropriate package with its sources which will be unpackages. I typically add a local changelog entry (set apart by a revision number as 1.2-3local0) and rebuild. This sometimes entails building dependencies. It all depends...

I guess gcc-4.5 is currently in experimental as per this page so you would have to add experimental to the sources.list file as well. I have not used this but it should work too:

deb-src http://ftp.debian.org/debian experimental main
Dirk Eddelbuettel
But who can I switch back and forth between 4.4 and 4.5?
michael
They simply co-exists on your system as the currently available gcc-4.3 and gcc-4.4 do, plus older ones you may have from prior Ubuntu installations. You can use the dpkg-alternatives mechanism to override the default priorities, and / or create shall aliases or links in /usr/local/bin.
Dirk Eddelbuettel