Ubuntu 12.04 comes with GCC compiler for C language only (not for c++).
First check which version of GCC ubuntu already installed. If it is <4.7.2 then proceed.
First check which version of GCC ubuntu already installed. If it is <4.7.2 then proceed.
- gcc is used to compile C program
- g++ is used to compile C++ program
- gcc -v (to check the gcc version)
- g++ -v (to check the g++ version)
- sudo apt-get update
- sudo apt-get install build-essential (to install g++ & some other other stuff)
- sudo apt-get update
- g++ -v (now check g++ is installed)
(Now add source from which we get GCC latest stable version)
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test
- sudo apt-get update
- sudo apt-get install gcc-4.7
- sudo apt-get install g++-4.7
- ls -lh /usr/bin/g++*
Install Alternatives(remember the version of gcc/g++):
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 10
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 20
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 10
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.7 20
- sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 (avoid the warning)
- sudo update-alternatives --set cc /usr/bin/gcc
- sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
- sudo update-alternatives --set c++ /usr/bin/g++
- gcc -v
- g++ -v (conform that you successfully installed the GCC)
configuring the default commands for gcc, g++:
- sudo update-alternatives --config gcc
- sudo update-alternatives --config g++
Source:
No comments:
Post a Comment