0

I currently have the gcc4.7 and the gcc4.7-base, etc., packages installed but GCC seems to still be using 4.6 when I call

gcc --version

I could compile the source code if I really needed it now, but I plan on converting some old code to have fun with C++11. If anyone has any suggestions on how to switch from 4.6 to 4.7 do tell.

I followed the guide from here :

https://askubuntu.com/questions/113291/installing-gcc-4-7

Edit: Fixed the issue, updated link to /usr/bin/gcc-4.7

Community
  • 1
  • 1
DubyaDubyaDubyaDot
  • 1,224
  • 2
  • 14
  • 24

3 Answers3

2

Try running the following to see where gcc is located:

ls -l `which gcc`

I'd say that odds are all you may need to do is update the link (but then again I can't check as I'm not booted into Linux at the moment)

Ross Aiken
  • 912
  • 1
  • 6
  • 16
  • I updated the link to /usr/bin/gcc-4.7 and now it works. thanks mate (and fellow Ross alike) – DubyaDubyaDubyaDot Apr 03 '12 at 01:18
  • In the interest of dumbing this down for simpletons like myself, could you please illustrate how to carry out this *update* as I am not clear as to which *link* it is you are referring to – puk Oct 22 '13 at 18:34
  • Above command will generate something like /usr/bin/gcc -> gcc-2.6. run 'rm /usr/bin/gcc', then 'ln -s gcc-2.7 /usr/bin/gcc'. Granted, haven't tested these commands, so use at your own risk – Ross Aiken Oct 24 '13 at 21:28
1

You can just set your CC environment variable to /usr/bin/gcc-4.7 or whatever it is. Or maybe your build system has a different way to choose which compiler to use.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • My `CC` variable is blank (I presume it was never set), if I do change it to `/usr/bin/gcc-4.7`, or "whatever it is", where would I make this change? In a startup file like `.bashrc`, in the shell, or some `configure` script or `makefile`? – puk Oct 22 '13 at 18:36
0

Chances are that many programs compiled for gcc 4.6 may not work for gcc 4.7. Hence you must keep both and at the same time make the link to gcc4.7 vary according to the situation. You can edit your gcc file to be a shell script :

#!/bin/sh
if [ -n "$GCC_SIX" ]; 
then
  exec /usr/bin/gcc-4.6 "$@"
else
  exec /usr/bin/gcc-4.7 "$@"
fi

Now, whenever you find a program not working on gcc4.7 just add a new environment variable and you have switched to gcc4.6 for the current execution. Notice that for a multi-user system, this can prove to be a life saver.

prathmesh.kallurkar
  • 5,468
  • 8
  • 39
  • 50
  • When you say "You can edit your gcc file to be a shell script", what gcc file are you referring to? Is this a system specific file, or just basically instead of calling `foo.c` you call `GCC_SIX=0; foo.sh` which calls `exec /usr/bin/gcc-4.X foo.c` – puk Oct 22 '13 at 18:39