2

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?

Community
  • 1
  • 1
bgarcial
  • 2,915
  • 10
  • 56
  • 123
  • 2
    CMake comes with a way to specify a standard in a compiler-agnostic way. – chris Feb 05 '18 at 18:10
  • Thanks I've been how to ... https://stackoverflow.com/questions/10851247/how-to-activate-c-11-in-cmake – bgarcial Feb 05 '18 at 18:24
  • Deciding which version to use for your project will depend on what platform(s) and compiler(s) you intend to use. – Jeff Melton Feb 05 '18 at 18:41
  • not sure if this sounds offensive, but if you dont know the difference between the standards, then maybe it doesnt matter which one you use. – 463035818_is_not_an_ai Feb 05 '18 at 18:45
  • @user463035818 your appreciation is correct and logic in relation to functions/libraries and so which I need to use. It's true, te more suited version to use is related with the needs that I have and is necessary know the standards to decide ... But my question is more related to currently, what standard is more used or complete? Is possible that this depend of my needs sure ... It's just that this variety generate in me this question https://isocpp.org/std/status – bgarcial Feb 05 '18 at 18:59
  • 1
    the question is offtopic. If it was not for being opinion-based it would be too broad. There are just too many things to consider. You can get many things from boost before they made it into a standard, but of course it is nicer to use the standard stuff. Moreover, different standards advocate slightly different styles (most prominently `auto`, lambdas, and more dont even exist prior to c++11), so you could use the one that fits you best. Always using the latest standard could also be a valid strategy... – 463035818_is_not_an_ai Feb 05 '18 at 19:12
  • 1
    This isn't a C++ or compiler question; this is a CMake question. – ams Feb 07 '18 at 11:03

1 Answers1

7

You can specify the standard with the -std switch

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

Issam
  • 141
  • 2
  • 2