Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update g++ but still old version

Tags:

c++

g++

upgrade

I installed g++ using those commands line:

sudo add-apt-repository ppa:jonathonf/gcc-7.1 
sudo apt-get update

Then

sudo apt-get install gcc-7 g++-7

When it was done I tried g++ -v but still shows me the old version

gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)

Am I not upgrading it correctly?

Edit

:~$ dpkg -L g++-7

/.
/usr
/usr/lib
/usr/lib/gcc
/usr/lib/gcc/x86_64-linux-gnu
/usr/lib/gcc/x86_64-linux-gnu/7
/usr/lib/gcc/x86_64-linux-gnu/7/cc1plus
/usr/share
/usr/share/doc
/usr/share/doc/gcc-7-base
/usr/share/doc/gcc-7-base/C++
/usr/share/doc/gcc-7-base/C++/README.C++
/usr/share/doc/gcc-7-base/C++/changelog.gz
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/x86_64-linux-gnu-g++-7.1.gz
/usr/bin
/usr/bin/x86_64-linux-gnu-g++-7
/usr/share/doc/g++-7
/usr/share/man/man1/g++-7.1.gz
/usr/bin/g++-7


:~$ which g++

/usr/bin/g++
like image 615
Ja_cpp Avatar asked Jul 20 '17 13:07

Ja_cpp


2 Answers

Installing a newer (or older) version of GCC than the Ubuntu default version via the package manager does not delete the default version. You get both. You can install as many versions as you like. gcc/g++ will continue to run the default version. If you have installed GCC 7, then you run the new compilers with gcc-7 or g++-7. For most build systems, it is sufficient to set the environment variables CC=gcc-7 CXX=g++-7 before starting the build.

like image 151
Mike Kinghan Avatar answered Nov 14 '22 08:11

Mike Kinghan


I installed the gcc-7 using the directions given in Ubuntu Forum, rebooted the system (to make sure all environment variables are loaded) and to compile with C++ 17, type the following on the shell : g++-7 -std=c++17 program_name.cpp -o program.out

Hope this helps.

like image 40
ggulgulia Avatar answered Nov 14 '22 08:11

ggulgulia