Which GNU g++ compiler

Hello Everyone
I am a new beginner who would like to start learning C++. The problem for me is which GNU g++ compiler do i install?

I am running Ubuntu MATE 19.04 (64-bit) and have absolutely no idea which GNU g++ compiler i should choose to install from Synaptic.

Hope someone can help me out here.

Thanks PeterP

The most up-to-date package seem to be g++-7 so that is what I would recommend. It should be alright for most of C++17.

If you need a later version you could always build and install GCC from source, but be warned, it can be a bit tricky and the build process alone can take quite a bit of time so I wouldn't recommend it unless you are an expert or absolutely need the latest features.
Last edited on
I don't know Ubuntu, but there might be properly packaged later versions:
https://packages.ubuntu.com/disco/g++-8
https://packages.ubuntu.com/disco/g++-9
Ah, apparently I got too many hits when searching for "g++" so it didn't show all of them.
I don't see why you wouldn't want to install g++-9 which is the latest version.
The package manager should install the most current version available for you.

Open a terminal and type the following:
sudo apt install build-essential

It will take a minute and look for stuff, then ask you if you want to download and install. Press Y, then have fun watching the text scrolling by.

After that you can use the GCC for both C and C++, at minimum.

$ cat > hello.cpp
#include <iostream>
#include <string>

int main( int argc, char** argv )
{
  std::string name = (argc > 1) ? argv[1] : "world";
  std::cout << "Hello " << name << "!\n";
}
^D

$ g++ -Wall -pedantic-errors -std=c++17 -O3 hello.cpp -o hello

$ ./hello Peter
Hello Peter!

$

That ^D is you pressing Ctrl+D, and the $ is the terminal prompt that you do not type.

Hope this helps.

[edit]
Fixed a typo. Thanks Ganado! :O)
Last edited on
Did a little reading on the subject and did eventually what Duthomhas suggested and use

sudo apt install build-essential

and the output of the above was: build-essential is already the newest version (12.6ubuntu1)

Thanks for all the help and advice everyone.
BTW, if you would like a nice IDE to go with that, I recommend Code::Blocks.
http://www.codeblocks.org/
It has a very nice editor and a lot of people like it.
Last edited on
Hello Duthomhas

Big thanks for the Code::Blocks link, but i think i'll stick with using the Terminal for now.

If you know of any C++ tutorials suitable for a noob like myself i'd really appreciate it.

Cheers mate.
Topic archived. No new replies allowed.