I recently had to use the C + + version of the Open Source library for stuttering, because it recommended using the gcc4.6 version, so I had to upgrade my gcc.
Luckily I was upgrading on the CentOS, and CentOS on it, and the easiest way was to upgrade to the g++4.7 version. Let's talk about how to upgrade g++:
Open the terminal, and then enter the following command:
CD/ETC/YUM.REPOS.D
wget http://people.centos.org/tru/devtools/devtools.repo
Yum--enablerepo= Testing-devtools-6 Install devtoolset-1.0
The three-line command above indicates that the installation is complete. Note that Devtoolset is actually a package that includes GCC, GDB, binutils, Elfutils, SystemTap, Valgrind, Oprofile, and DWZ.
If you only need to install GCC, then you can specify only GCC:
Yum-y--enablerepo=testing-1.1-devtools-6 Install DEVTOOLSET-1.0-GCC devtoolset-1.0-gcc-c++
Since CentOS is generally used as a server, we generally do not change the GCC version easily. So the directory installed here is:/opt/centos/devtoolset-1.0/root/. You can see that there are a lot of files in it.
To start using g++, you must export its path, so continue typing in the terminal:
Export path=/opt/centos/devtoolset-1.0/root/usr/bin/: $PATH
After export, you can try the g++ version now. In the terminal, enter:
g++--version
This is the terminal output is:
g++ (GCC) 4.7.0 20120507 (Red Hat 4.7.0-5)
Copyright (C) Free Software Foundation, Inc.
This is free software; The source for copying conditions. There is NO
warranty, not even to merchantability or FITNESS for A particular.
If you want to keep using this version of g++, you can set the g++ to the system's environment variable. But be careful, it can lead to dependency problems. The methods of modification are:
Method 1: Use the/opt/centos/devtoolset-1.0/root to enable file
Echo ' source/opt/centos/devtoolset-1.1/enable ' >> ~/.bash_profile
source/opt/centos/devtoolset-1.1/ Enable
It is recommended that you set the script '/opt/centos/devtoolset-1.0/enable ' By default environment variables given by GCC, and add it to the environment variables that require the user.
Method 2: Modify profile file:
#vi/etc/profile
In the inside add:
Export path= "/opt/centos/devtoolset-1.0/root/usr/bin/: $PATH"
Method 3: Modify the. bashrc file:
# VI/ROOT/.BASHRC
In the inside add:
Export path= "/opt/centos/devtoolset-1.0/root/usr/bin/: $PATH"
Note: These 3 methods generally need to unregister the system or source before it takes effect, and finally you can test it by using the echo command:
# echo $PATH
See if there is already a/opt/centos/devtoolset-1.0/root/usr/bin/this path in the output.