I followed the tutorial on this webpage: https://code.visualstudio.com/docs/cpp/config-clang-mac to be able to compile c++ programs using VS Code. After doing all things requested, I am able to compile and to debug the c++ file.
However, it seems that there is an issue. In the box "PROBLEMS", I have the two following errors:
expected ';' at end of declaration [9, 23]
range-based for loop is a C++11 extension [-Wc++11-extensions] [11, 29]
My code is exactly the same as the one reported in the VS code website. I also checked all *.json files and c++17 is the default compiler.
The tasks.json is as follows:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
The c_cpp_properties.json is as follows:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
When compiling, everything is fine:
> Executing task: /usr/bin/clang++ -std=c++17 -stdlib=libc++ -g /Users/stephane/Documents/c++/causality/run_mainfile.cpp -o /Users/stephane/Documents/c++/causality/run_mainfile <
Terminal will be reused by tasks, press any key to close it.
Here is the screenshot:
I am using macOS 10.15.6, VS Code 1.47.1, and C/C++ extension v0.29.
Any ideas?
@RangerBob The solution is simply what @brc-dd said but you don't have to create a new project/directory. Go to Preferences > Search > "c++ standard". Choose C++17, and VS Code will create a new file "settings.json" with that standard causing the 3 warnings to disappear.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.