Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile c++14-code with g++

I'm using g++ 4.8.4 on Ubuntu 14.04 LTS. When trying to compile with '-std=c++14', I get this error:

g++: error unrecognized command line option '-std=c++14' 

Compiling with '-std=c++11' works fine, so I'm not sure what's going on. Does g++ really have no support for c++14 yet? Am I using a wrong command line option?

I used "sudo apt-get install g++" which should automatically retrieve the latest version, is that correct?

like image 866
Silverlan Avatar asked Aug 12 '15 12:08

Silverlan


People also ask

Can I compile C code with g ++?

g++ also has additional macros. So you can compile C code with g++ and in fact mix both C and C++ code.

Does G ++ support C ++ 14?

G++ does support C++14 both via -std=c++14 and -std=c++1y . The latter was the common name for the standard before it was known in which year it would be released.

How do I compile C ++ 20 with G ++?

To enable C++20 support, add the command-line parameter -std=c++20 (use -std=c++2a in GCC 9 and earlier) to your g++ command line. Or, to enable GNU extensions in addition to C++20 features, add -std=gnu++20 . Important: Because the ISO C++20 standard is very recent, GCC's support is experimental.

How do I compile C++ program using G ++ in terminal?

cpp file that you want to compile, follow the following instructions to compile and run it. Step 1 − Open a new terminal window or cmd if you are on windows. Step 3 − Now enter the following command to compile the source file using g++. In place of <name-you-want-to-give> replace it by any name like myprogram, etc.


1 Answers

For gcc 4.8.4 you need to use -std=c++1y in later versions, looks like starting with 5.2 you can use -std=c++14.

If we look at the gcc online documents we can find the manuals for each version of gcc and we can see by going to Dialect options for 4.9.3 under the GCC 4.9.3 manual it says:

‘c++1y’

The next revision of the ISO C++ standard, tentatively planned for 2014. Support is highly experimental, and will almost certainly change in incompatible ways in future releases.

So up till 4.9.3 you had to use -std=c++1y while the gcc 5.2 options say:

‘c++14’ ‘c++1y’

The 2014 ISO C++ standard plus amendments. The name ‘c++1y’ is deprecated.

It is not clear to me why this is listed under Options Controlling C Dialect but that is how the documents are currently organized.

like image 110
Shafik Yaghmour Avatar answered Sep 28 '22 07:09

Shafik Yaghmour