Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm a linux virgin and have only been programming c++ for 2 weeks, so please bear with me.

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?

share|improve this question
    
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"? –  Reed Kraft-Murphy Feb 3 '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) –  Gracchus Feb 3 '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 3 '13 at 22:41
    
@ReedKraft-Murphy thank you reed! i've moved it here unix.stackexchange.com/questions/63587/… –  Gracchus Feb 3 '13 at 22:42
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
    
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? –  Gracchus Feb 3 '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 3 '13 at 21:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.