50

I wish to install gcc 4.7 so that I can use some c++11 features.

I downloaded the source, ran ./configure and was told I needed GMP. Downloaded the code for that, hit ./configure and was told I needed m4. But I already have m4 (least that is what synamptic tells me).

What is going on and how can I fix it?

Braiam
  • 67,791
  • 32
  • 179
  • 269
soandos
  • 1,155

4 Answers4

62

You can try this PPA for installing gcc 4.7. Do note that it has packages only for 12.04 and not for 11.10.

Run the following commands in a terminal:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.7

Or, if you prefer a graphical way of installing a PPA, take a look at What are PPAs and how do I use them?.

jokerdino
  • 41,320
  • 2
    If you want to replace gcc 4.6 and make gcc 4.7 the default gcc compiler, you have to follow these instructions – thegreendroid Nov 18 '12 at 02:32
  • I didn't have add-apt-repository installed, I fixed this with sudo apt-get install python-software-properties – dwurf Dec 06 '13 at 00:23
  • Then do this http://askubuntu.com/questions/269257/how-to-activate-gcc-4-7-version and repeat the same steps for G++. – Antonio Petricca Feb 19 '16 at 08:27
  • This is an old answer, we are now in ubuntu 17.04, shoudl it perhaps be edited, or does it only work for 12.04 still? – Ander Biguri Apr 25 '18 at 11:31
  • If you would be so kind to let me take advantage of your Compiz / CCSM skills, I'm stumped and posted a question: https://askubuntu.com/q/1348326/307523 TIA – WinEunuuchs2Unix Jun 27 '21 at 18:57
30

NOTE!!

You also most likely need to take care of g++-4.7

So the full commands list will be:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.7 g++-4.7

Also, don't forget to update-alternatives, as suggested here

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7 
sudo update-alternatives --config gcc

This is confirmed to work in Ubuntu 12.04

0

Search the build directory for config.log files, and search those for the error message. That should give some clues.

BTW, if you don't need 4.7 precisely, you could try installing the gcc-snapshot package. That should have the features you need. It doesn't get installed in the standard place though, if I remember correctly.

ams
  • 3,019
0

This is a complete guide of how to build from sources gcc-4.7 on Ubuntu 12.04 64 bits:

http://solarianprogrammer.com/2012/04/13/building-gcc-4-7-on-ubuntu-12-04/

mmisu
  • 1
  • That guide makes the second common mistake given at http://gcc.gnu.org/wiki/InstallingGCC, making life far more complicated than it needs to be – Jonathan Wakely Feb 20 '13 at 11:40