How to manage C++ standard [EXPERIMENTAL]


This is an experimental feature subject to breaking changes in future releases.

The setting representing the C++ standard is cppstd. The detected default profile doesn’t set any value for the cppstd setting.

The consumer can specify it in a profile or with the -s parameter:

conan install . -s cppstd=gnu14

This setting will only be applied to the recipes specifying cppstd in the settings field:

 class LibConan(ConanFile):
     name = "lib"
     version = "1.0"
     settings = "cppstd", "os", "compiler", "build_type", "arch"

Valid values for compiler=Visual Studio:

14 C++ 14
17 C++ 17
20 C++ 20 (Still C++20 Working Draft)

Valid values for other compilers:

98 C++ 98
gnu98 C++ 98 with GNU extensions
11 C++ 11
gnu11 C++ 11 with GNU extensions
14 C++ 14
gnu14 C++ 14 with GNU extensions
17 C++ 17
gnu17 C++ 17 with GNU extensions
20 C++ 20 (Partial support)
gnu20 C++ 20 with GNU extensions (Partial support)

Build helpers

When the cppstd setting is declared in the recipe and the consumer specify a value for it:

  • The CMake build helper will set the CONAN_CMAKE_CXX_STANDARD and CONAN_CMAKE_CXX_EXTENSIONS definitions, that will be converted to the corresponding CMake variables to activate the standard automatically with the conan_basic_setup() macro.
  • The AutotoolsBuildEnvironment build helper will adjust the needed flag to CXXFLAGS automatically.
  • The MSBuild/VisualStudioBuildEnvironment build helper will adjust the needed flag to CL env var automatically.

Package compatibility

By default Conan will detect the default standard of your compiler to not generate different binary packages. For example, you already built some gcc > 6.1 packages, where the default std is gnu14. If you introduce the cppstd setting in your recipes and specify the gnu14 value, Conan won’t generate new packages, because it was already the default of your compiler.


Check the package_id() reference to know more.