How to enable C++17 compiling in Visual Studio?

189,688

Solution 1

There's now a drop down (at least since VS 2017.3.5) where you can specifically select C++17. The available options are (under project > Properties > C/C++ > Language > C++ Language Standard)

  • ISO C++14 Standard. msvc command line option: /std:c++14
  • ISO C++17 Standard. msvc command line option: /std:c++17

Visual Studio 2022 (MSVC C++20 and the /std:c++20 Switch - C++ Team Blog):

  • ISO C++20 Standard. msvc command line option: /std:c++20

Any Visual Studio:

  • The latest draft standard. msvc command line option: /std:c++latest

Solution 2

MSBuild (Visual Studio project/solution *.vcproj/*.sln):

Add to Additional options in Project Settings: /std:c++latest to enable latest features - currently C++17 as of VS2017, VS2015 Update 3.

https://blogs.msdn.microsoft.com/vcblog/2016/06/07/standards-version-switches-in-the-compiler/

/permissive- will disable non-standard C++ extensions and will enable standard conformance in VS2017.

https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/

EDIT (Oct 2018): The latest VS2017 features are documented here:

https://docs.microsoft.com/en-gb/cpp/build/reference/std-specify-language-standard-version

VS2017 supports: /std:[c++14|c++17|c++latest] now. These flags can be set via the project's property pages:

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Working with Project Properties.
  2. Select Configuration Properties, C/C++, Language.
  3. In C++ Language Standard, choose the language standard to support from the dropdown control, then choose OK or Apply to save your changes.

CMake:

Visual Studio 2017 (15.7+) supports CMake projects. CMake makes it possible to enable modern C++ features in various ways. The most basic option is to enable a modern C++ standard by setting a target's property in CMakeLists.txt:

add_library (${PROJECT_NAME})
set_property (TARGET ${PROJECT_NAME}
  PROPERTY
    # Enable C++17 standard compliance
    CXX_STANDARD 17
)

In the case of an interface library:

add_library (${PROJECT_NAME} INTERFACE)
target_compile_features (${PROJECT_NAME}
  INTERFACE
    # Enable C++17 standard compliance
    cxx_std_17
)

Solution 3

Visual Studio 2015 Update 3 does not support the C++17 feature you are looking for (emplace_back() returning a reference).

Support For C++11/14/17 Features (Modern C++)

C++11/14/17 Features In VS 2015 RTM

VS 2015 Update 2’s STL is C++17-so-far Feature Complete

Visual Studio 2015 Update 3

STL Fixes In VS 2015 Update 3

Solution 4

Visual studio 2019 version:

The drop down menu was moved to:

  • Right click on project (not solution)
  • Properties (or Alt + Enter)
  • From the left menu select Configuration Properties
  • General
  • In the middle there is an option called "C++ Language Standard"
  • Next to it is the drop down menu
  • Here you can select Default, ISO C++ 14, 17 or latest

Solution 5

If bringing existing Visual Studio 2015 solution into Visual Studio 2017 and you want to build it with c++17 native compiler, you should first Retarget the solution/projects to v141 , THEN the dropdown will appear as described above ( Configuration Properties -> C/C++ -> Language -> Language Standard)

Share:
189,688

Related videos on Youtube

Tudvari
Author by

Tudvari

Making games while working at a dayjob. Check out my YouTube channel: http://www.youtube.com/Tudvari

Updated on March 03, 2022

Comments

  • Tudvari
    Tudvari about 2 years

    I want to use C++17 features.

    How can I switch compiling from C++14 to C++17 in Microsoft Visual Studio?

    Or it's not avaiable in release versions of VS?

    • ildjarn
      ildjarn over 7 years
      Which C++17 features? Which version of Visual Studio? If you're asking about C++17 why did you tag your question c++11 and c++14?
    • Tudvari
      Tudvari over 7 years
      c++17 wasn't available, and I thought that those who are interested in specific versions of C++ knows better how to switch it. For example I want std::vector.emplace_back() to give back a reference to the newly created element. I know that +1 line, and I get that reference, But I would like to know the answer to my question anyway. VS Community 2015 (14.0.25431.01 Update 3)
    • Mikel F
      Mikel F over 7 years
      You should probably check here: blogs.msdn.microsoft.com/visualstudio
    • Praetorian
      Praetorian over 7 years
      You can't enable specific language dialects in VS, you get whatever they've implemented. You might have pretty good luck with standard library features voted into C++17 if you're using VS21015, but not so much with language features.
    • Semyon Burov
      Semyon Burov over 7 years
      Check this out: visualstudio.com/vs/visual-studio-2017-rc . VS 2017 rc should probably support new c++17 features
    • Yakk - Adam Nevraumont
      Yakk - Adam Nevraumont over 7 years
      @preat MSVC 2017 has a "latest" setting, but that is not released yet.
  • Roi Danton
    Roi Danton almost 6 years
    The syntax -std:c++14, -std:c++17 and -std:c++latest also works, e.g. when you prefer to manually enter compiler options (tested with VS2017).
  • Johan Lundberg
    Johan Lundberg almost 6 years
    Is that not clear from the answer already, or do you specifically mean - instead of the /std: switches I list?
  • Roi Danton
    Roi Danton almost 6 years
    I see the benefit when coming from gcc or clang. Then the - is less intrusive (however the syntax still differs slightly (: instead of =)).
  • Babar-Baig
    Babar-Baig over 4 years
    In VS 2019, to get to Project Properties, go to "Solution Explorer", right-clicked on the project title and select Properties. Then follow directions of this post.
  • Johan Lundberg
    Johan Lundberg over 4 years
    @BabarBaig, that works but the way I described it works just as before. You need to "be" in the relevant project, for example by opening a source code file or selecting the it in the solution explorer.
  • Andrei Krasutski
    Andrei Krasutski over 4 years
    ISO C++20 what version of the Visual Studio?
  • Johan Lundberg
    Johan Lundberg over 4 years
    @AndreiKrasutski. There is no ISO C++20 yet but some support in /std:c++latest. The C++20 standard is expected next year. I Edited in a comment in my answer.
  • Travis Su
    Travis Su about 4 years
    I did the dropdown in my VS2017 but still the compiler keep applying C++98 standard, what the heck
  • pixel
    pixel over 3 years
    What C++ standard is used if there is nothing selected in Visual Studio 2017 > Project Properties > C / C++ > Language > C++ Standard dropdown? I have 14, 17 and latest in the dropdown, but none is selected, so how do I find what c++ standard is used in a project in that case?
  • Persixty
    Persixty over 3 years
    Remember to do this for 'All Configurations' and 'All Platforms'. That's from someone who's spent an 2 hour figuring out why it still doesn't work! But thanks for the answer.
  • Antony Hatchkins
    Antony Hatchkins about 3 years
    @pixel It looks as though the default is still C++14 in VS2019: github.com/MicrosoftDocs/cpp-docs/blob/master/docs/build/…
  • J-D3V
    J-D3V over 2 years
    There is no Visual Studios 2020, this is for V.S. Code
  • Ahx
    Ahx over 2 years
    But the question is not asking "only-for" VS Studio. If you re-read the question, at the end of the line "it's not avaiable in release versions of VS?". The question is flexible, no need to be strict.
  • J-D3V
    J-D3V over 2 years
    This question is not that flexible, and if it were, it would need to be closed. It wouldn't be focused enough. VS Code is not a different version of Visual studio. One is an Integrated Development Environment, and one is an Editor. One pulls up the code that you write, the other is embedded into the file system of the project it is working on. One is funded by Microsoft, one is developed by Microsoft. One is portable to Linux, one is not. A configuration for one, will not work for the other. You might as well answer how to compile C++17 in Notepad.
  • zBeeble
    zBeeble over 2 years
    In the vs2019 that Unreal setup, there is no Configuration Settings -> General -> C++ Language Standard. Can it be added? There is an nmake -> Additional Options that is set to /std:c++14 ... but changing it to c++17 doesn't seem to work.
  • Admin
    Admin about 2 years
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.