bgarcial
bgarcial

Reputation: 3183

How to meet the C++ standards version in my g++ compiler?

I know C++ has standards and not versions, therefore, their releases are managed by specifications (like C99, C++11, between others)

The C++ compilers have versions, and a each version can support multiple c++ standards ... Is this right?

In relation to above, I found my g++ version compiler, which is 7.2.0

λ bgarcial [~] → g++ --version
g++ (Ubuntu 7.2.0-8ubuntu3) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  
λ bgarcial [~] → 

I have the following directory of my g++ compiler, I am using native makefiles to build in C++ language

λ bgarcial [include/c++/7] → pwd
/usr/include/c++/7

λ bgarcial [include/c++/7] →

How to can I determine which C++ standards that are supported my g++ compiler?

The g++ documentation includes the following information:

GCC supports the original ISO C++ standard published in 1998, and the 2011 and 2014 revisions. The default, if no C++ language dialect options are given, is -std=gnu++14.

It also contains this interesting bit:

By default, GCC also provides some additional extensions to the C++ language that on rare occasions conflict with the C++ standard. See Options Controlling C++ Dialect. Use of the -std options listed above disables these extensions where they they conflict with the C++ standard version selected.

You may also select an extended version of the C++ language explicitly with -std=gnu++98 (for C++98 with GNU extensions), or -std=gnu++11 (for C++11 with GNU extensions), or -std=gnu++14 (for C++14 with GNU extensions), or -std=gnu++1z (for C++1z with GNU extensions).

In a given C++ project, how can I specify what C++ standard/specification type to use?

In the CMakeLists.txt may be? or ...

As a flag building some basic file? such as the following:

g++ client.cpp main.cpp -o client.out -lzmq -std=gnu++11

What is the recommended C++ standard/specification.

I ask this because in first instance I assume that I am using C++14 with GNU extensions in relation to g++ compiler documentation previously referenced above. In some cases, I am not using some functions or libraries but I don't know if this is due to the standard used or something else.

What is the recommended C++ standard to use and how can I configure my project to use it?

Upvotes: 2

Views: 4959

Answers (1)

Issam
Issam

Reputation: 161

You can specify the standard with the -std switch

$g++ -std=c++11 your_file.cpp -o your_program

Upvotes: 7

Related Questions