Search code examples
visual-studio-codeclang++vscode-remote

why cant my vscode check for C++17 (my compiler is clang 12)?


This follow is my remote server and local vscode

this follow context

    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang++-12",
            "cStandard": "gnu11",
            "cppStandard": "c++17",
            "intelliSenseMode": "linux-clang-x64",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
} 

in my remote c_cpp_properties.json under .vscode folder

settings.json:

"C_Cpp.default.cppStandard": "c++17",
    "clang.cxxflags": [
        "-std=c++17"
    ],

but my code can be compiled


Solution

  • This problem is because of a cmake tool plugin, find your compile_commands.json file in your remote server, and edit to add the option -std=c++17; thus, change e.g.

    "command": "/usr/bin/clang++-12   -g -o CMakeFiles/linuxCode.dir/main.cpp.o -c  /home/source/main.cpp",
    

    to

    "command": "/usr/bin/clang++-12   -g -o CMakeFiles/linuxCode.dir/main.cpp.o -c -std=c++17 /home/source/main.cpp",