6

I'm about to update default GCC (version 4.6.3) shipped by Ubuntu 12.04 to 4.8.2, though the compilation requires a standalone C++ compiler

admin@ubuntu: /usr/local/gcc_build$ sudo make

ends up with

configure: error: C++ compiler missing or inoperational
make[2]: *** [configure-stage1-libcpp] Error 1

Therefore I turn to the process of g++ installation with a preference to the latest version, which means that I would like to compile from source directly rather than apt-get. But seriously, I can't find the source anyway!(O_o). On the other hand, does the source of GCC also come along with that of g++ in the tar file I downloaded, or not? Thanks.

PS: problem remains unsolved with admin@ubuntu: /usr/local/gcc_build$ /home/admin/gcc-4.8.2/configure --enable-languages=c,c++

Y.Z
  • 626
  • 2
  • 9
  • 21

3 Answers3

11
  1. Add the ppa by

    sudo add-apt-repository ppa:ubuntu-toolchain-r/test

  2. Install g++ and gcc (version 4.8)

    sudo apt-get update; sudo apt-get install gcc-4.8 g++-4.8

  3. Run the following commands one by one,

    sudo update-alternatives --remove-all gcc

    sudo update-alternatives --remove-all g++

    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20

    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20

    sudo update-alternatives --config gcc

    sudo update-alternatives --config g++

That's it you are done!

Community
  • 1
  • 1
TheNormalGuy
  • 371
  • 3
  • 16
  • As far I I know, this installed g++ 4.8.1. – skyuuka Dec 17 '15 at 00:36
  • In my case I didn't have any alternatives installed and I wanted to be able to switch back to 4.6 if needed. I had to install the old alternatives with `sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20` and `sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20`. Now I can use `sudo update-alternatives --config gcc` and `sudo update-alternatives --config g++` to easily change the version any time. – Bart C Nov 30 '16 at 12:14
3

You can easily compile the sources.

The following commands worked for gcc 4.7. They should be fine for gcc 4.8 as well:

sudo apt-get install libmpfr-dev libgmp3-dev libmpc-dev flex bison

svn checkout svn://gcc.gnu.org/svn/gcc/trunk

cd trunk

./configure --prefix=/opt/gcc-4.8.2/usr/local/gcc-4.8.2 --enable-languages=c,c++

make

make install

The compiler will be placed in the /opt/ directory, so you have to use it from there.

Claudio
  • 10,614
  • 4
  • 31
  • 71
  • Ok I missed configuration about `--enable-languages`. But are you sure flex and bison are essential? – Y.Z Nov 07 '13 at 13:16
  • Yes, they are (don't know why, but without them the compilation stopped complaining...) – Claudio Nov 18 '13 at 12:00
  • 1
    I assume that without the --prefix flag, gcc will be installed in the appropriate directory, and after make install, "gcc --version" will show 4.8.2? – Trevor Hickey Mar 17 '14 at 20:05
  • @Claudio Thanks, this has been extremely helpful. Only two things: A complaint about a missing `bits/predefs.h` is fixed by `C_INCLUDE_PATH=/usr/include/x86_64-linux-gnu/ make` instead of `make`; and a complaint about a missing `gnu/stubs-32.h` is fixed by `sudo apt-get install libc6-dev-i386`. – iavr Mar 27 '14 at 22:03
  • @TrevorHickey I did that at the end of November. `gcc --version` showed `4.9.0`. I'm doing it again now, who knows. – iavr Mar 27 '14 at 22:08
  • CAUTION: The `make` above failed! `../.././libcc1/findcomp.cc:20:20: fatal error: config.h: No such file or directory compilation terminated.` – gsamaras Jan 15 '15 at 04:48
  • `apt-get build-deps gcc` is better. – Ciro Santilli OurBigBook.com Jul 29 '15 at 11:26
1

Do you want to compile it yourself ? If not, there is a PPA, described here

marcolz
  • 2,880
  • 2
  • 23
  • 28