5

I'm trying to set the default g++ to 4.7.2 which I'm told by my host is installed (I'm also told that c++11 is also installed); however, neither of us know how to set the default g++ to 4.7.2 because g++ --version 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.

I tried these sudo commands here, but I just found out that they don't work because CentOS uses yum.

How can I set the default g++ to 4.7.2 (if it's even installed) on CentOS 5.9?

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
  • The stock version of gcc in the CentOS repos is 4.1.2 (with the option of 4.4). Have you tried [this answer to "Install gcc 4.7 on CentOS"](http://superuser.com/a/542091/191578)? – Reed Kraft-Murphy Feb 03 '13 at 22:32
  • 1
    @ReedKraft-Murphy sorry for deleting that last post out from under you. I saw your answer too late. when i do the `yum --enablerepo=testing-devtools-6 install devtoolset-1.0-gcc` line, it gives `Error getting repository data for testing-devtools-6, repository not found`. Thank you for helping! (I'm going to ask this in a formal question) –  Feb 03 '13 at 22:34
  • No worries. Since you're on CentOS 5.x, rather than 6.x, I'm guessing you'll need to say `yum --enablerepo=testing-devtools-5 ...` rather than `testing-devtools-6`, but I'll happily take this to a formal question :) – Reed Kraft-Murphy Feb 03 '13 at 22:41
  • @ReedKraft-Murphy thank you reed! i've moved it here http://unix.stackexchange.com/questions/63587/how-to-install-g4-7-2-c11-on-centos –  Feb 03 '13 at 22:42

1 Answers1

1

You need to set the CXX environment variable. For example, export CXX="/usr/bin/g++-4.7" . And CC is the one that controls the C compiler.

schaiba
  • 7,493
  • 1
  • 33
  • 31
  • Thank-you for looking! I tried that, and I'm still getting the same result for `--version`. I tried executing `/usr/bin/g++-4.7`. Does that mean it's not even installed? –  Feb 03 '13 at 21:42
  • Well, the path in my answer was only an example. If you don't know if/where the newer g++ is, it's gonna be more difficult. – schaiba Feb 03 '13 at 21:46
  • in centOS 6 you will find it here: /opt/rh/devtoolset-3/root/usr/bin/gcc – Saleh Abdulaziz Jun 13 '18 at 23:37