1

My host has installed c++11 and g++ 4.7.2 (I'm told), but we can't figure out how to set 4.7.2 to default as g++ --version still says I'm 4.1.2.

Stack has shown me that I can't sort multidimensional vector of ints? without cc1plus: error: unrecognized command line option "-std=c++11" with g++, but all of the answers I come across for setting the default don't seem to work.

CentOS 5.9

I'm using CentOS 5.9, and I have no idea if that's the issue, but I tried g++-4.7 and g++-4.7.2 from How to change version of g++ compiler from 4.1.2 to 4.5?, but SSH says sudo: apt-get: command not found and -bash: g++-4.7: command not found for both (.2 for .2). If I put a space before -4.7, it says g++: unrecognized option '-4.7'.

I tried the suggested solution from the A of my last c++ q here, and the command executes without error, but nothing is returned, and g++ --version still gives:

g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

GCC?

I've seen this associated with g++ on many links, but I don't even know what it is, and I'm afraid to try this for risk of nuking my system.

My host says this is the limit of their support, so I'm totally on my own. Also, please understand that I just started C++ a week or two ago and have no knowledge of linux.

Please help! Many thanks in advance!

Community
  • 1
  • 1
  • 2
    Try the good old `find / -name g++\*`. – Hristo Iliev Feb 03 '13 at 20:48
  • @HristoIliev thank-you! I did that, and it showed 2 files: `/usr/share/man/man1/g++.1.gz` and `/usr/bin/g++` –  Feb 03 '13 at 20:52
  • Then GCC 4.7.2 is nowhere to be found on your system. Perhaps you have been told wrong. – Hristo Iliev Feb 03 '13 at 23:34
  • @HristoIliev yup, just found out. admin just used default `yum` which only installs 4.1.2 even with latest centos rpms. now, i'm stuck on this http://unix.stackexchange.com/questions/63587/how-to-install-g4-7-2-c11-on-centos thank you for your help! –  Feb 03 '13 at 23:36

1 Answers1

4

When you have multiple applications providing similar functionality, official mechanism to choose preferred application is update-alternatives.

Try using this:

 sudo update-alternatives --config g++

If you have more than one version of gcc installed, it will give you option to make one of them default.

Sometimes, alternatives are not installed - probably omission by package maintainer. You can fix it by installing it manually, something like this:

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

Alternatively, you can create symbolic links directly to desired g++/gcc from your ~/bin, and add $HOME/bin to the beginning of your PATH. See more details in this answer.

Community
  • 1
  • 1
mvp
  • 111,019
  • 13
  • 122
  • 148
  • thank-you! someone else suggested that, and I tried, but it just looks like it executes without error, prints nothing, and returns to the command line –  Feb 03 '13 at 20:56
  • sometimes alternative is not installed. I have updated my answer with info how to fix it. There is also 3rd way with using local symlinks (to leave system gcc alone). – mvp Feb 03 '13 at 21:02
  • do you think it's because I'm using CentOS 5.9? neither commands worked. do you know how to check if g++ 4.7.2 is truly installed (not just in the path or whatever with `g++ --version`)? –  Feb 03 '13 at 21:07
  • `rpm -qa | grep g++`. as last resort, using [this approach](http://stackoverflow.com/questions/13365348/is-it-possible-to-build-aosp-project-gingerbread-in-kubuntu12-04-xubuntu/13415103#13415103) will definitely work – mvp Feb 03 '13 at 21:13
  • I just found out that CentOS uses `yum` not `sudo`. Do you happen to know what the alternative commands would be? Thanks a lot for all of your help on this! –  Feb 03 '13 at 21:14
  • it is possible that `sudo` is not configured. in that case `su` to root, and then execute provided commands without `sudo` prefix. – mvp Feb 03 '13 at 21:15
  • @JoeCoderGuy: `yum` and `sudo` do different things. You can't replace one with the other. CentOS has both. – Lightness Races in Orbit Feb 03 '13 at 21:38