首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VS代码c++ for macOS:编译工作但VS代码检测错误

VS代码c++ for macOS:编译工作但VS代码检测错误
EN

Stack Overflow用户
提问于 2020-07-16 15:29:20
回答 1查看 1.7K关注 0票数 5

我遵循了这个网页上的教程:https://code.visualstudio.com/docs/cpp/config-clang-mac,以便能够使用VS代码编译c++程序。在完成所有要求的事情后,我能够编译和调试c++文件。

然而,似乎存在一个问题。在“问题”框中,我有以下两个错误:

期望“;”在声明9,23末尾

基于范围的循环是一个C++11扩展-Wc++11-扩展

我的代码与VS代码网站中报告的代码完全相同。我还检查了所有*.json文件,c++17是默认编译器。

tasks.json如下:

代码语言:javascript
复制
{
// 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
    }
  }
]

}

c_cpp_properties.json如下:

代码语言:javascript
复制
{
"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

}

编译时,一切都很好:

代码语言:javascript
复制
> 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.

这是截图:

我使用的是macOS 10.15.6、VS代码1.47.1和C/C++扩展v0.29。

有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2021-11-04 15:35:07

@RangerBob解决方案只是@brc所说的,但您不必创建一个新的项目/目录。转到Preferences > Search > "c++标准“。选择C++17,VS代码将创建一个新的文件"settings.json“与该标准导致3警告消失。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62938142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档