Changing an existing project to C++17

Sysprogs forums Forums VisualGDB Changing an existing project to C++17

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #25906
    Ophidian14
    Participant

    I have an existing project which was using C++11 and the headers/libs from GCC 4.8.5.  This project is now using the headers/libs from devtoolset-8 (gcc 8.3.1) and C++17.  How do I go about editing my project file so that it reflects this?  I got my Intellisense include directories in order, but it’s telling me errors such as “no such template ‘optional’ in namespace std” which makes me think it’s not picking up C++17.  I did try creating a new project and selecting C++17 with the wizard, and this worked, but I would like to keep my existing project file.  I noticed the new project contained this:

    <ItemDefinitionGroup Condition=”‘$(Configuration)|$(Platform)’==’Debug|VisualGDB'”>
    <ClCompile>
    <CPPLanguageStandard>CPP1Z</CPPLanguageStandard>
    </ClCompile>
    </ItemDefinitionGroup>

     

    which I added to my new project but it did not make a difference ( I got the same error).

    #25909
    Ophidian14
    Participant

    Also I’d like to ask a slightly different related question.  I follow the following steps:

    1.  Create a new Linux Cmake project targeting C++17.
    2.  Manually add the /opt/rh/…. include paths for devtoolset-8.
    3.  Add #include <optional> and declare a std::optional<int>.
    4.  I seemingly have to restart my project for the changes in #2 to correctly reflect in #3 (otherwise my usage of optional is red underlined and unrecognized) but I am not worried about this.

    At this point I change from Cmake build to Custom build step.  Immediately I lose support for C++17 and std::optional, they go red squiggly and the error console says “namespace std has no template optional” or something like that.  My question is, why does changing the build type lose me the C++17 support and how would I reintroduce it?

    #25932
    support
    Keymaster

    Hi,

    For MSBuild-based projects you can set the C++ language standard via VS Project Properties (not VisualGDB Project Properties) -> C/C++ -> Advanced -> Language Standard for C++ files (that will set the CPPLanguageStandard value in the .vcxproj file). If you believe this causes an error, please identify whether it affects building or only IntelliSense and whether you are using Clang IntelliSense or the regular VC++ IntelliSense.

    If the project cannot be built, your compiler may not support C++17. If the problem is specific to IntelliSense only, please try reproducing it on a clean project and let us know the exact repro steps (see the 3-step format here).

    Regarding the CMake projects, please try using the new Advanced CMake Project Subsystem. It automatically keeps the IntelliSense settings synchronized with the actual build settings, eliminating the need for any manual setup. If you would like to use the old CMake project system (based on VC++ projects), you would need to manually add the “–std=” option to VisualGDB Project Properties -> IntelliSense -> Additional flags for C++ files.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.