首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VScode C/C++扩展设置和配置(macOS)

VScode C/C++扩展设置和配置(macOS)
EN

Stack Overflow用户
提问于 2022-06-03 14:51:04
回答 1查看 481关注 0票数 0

我是C++新手,还在尝试在vscode中设置C/C++扩展。

我遵循了vscode官员提供的本教程:https://code.visualstudio.com/docs/cpp/config-clang-mac#_cc-configuration

完成"lauch.json“、"tasks.json”和"c_cpp_properties.json“文件后,我单击了"play”图标,但调试器仍然会显示";“并打开launch.json文件。

我认为我在这篇文章中遇到了同样的问题,但它的解决方案未能解决我的问题:Mac VSCode Debugger always show error about ';' and ':'

这是我的密码:

代码语言:javascript
复制
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
vector<string> msg {"Hello", "C++++", "World", "from", "VS Code", "and the C++ extension!"};

for (const string& word : msg)
{
    cout << word << " ";
}

vector<string> aaa {"H", "E", "L", "L", "O"};
for (const string& word : aaa)
{
    cout << word << " ";
}


cout << endl;
}

这是我的launch.json文件:

代码语言:javascript
复制
    {
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        
        
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "enter program name, for example ${workspaceFolder}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ]
}

这是我的tasks.json文件:

代码语言:javascript
复制
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

这是我的c_cpp_properties.json文件:

代码语言:javascript
复制
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
            ],
            "macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2022-06-04 02:04:56

问题是program字段在launch.json中不正确,如果您的CPP名称是your-program.cpp,则可以将program字段设置为your-program

因为编译输出文件名是"${fileDirname}/${fileBasenameNoExtension}",正如您在tasks.json中设置的那样

代码语言:javascript
复制
    {
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "your-program", // set it to right name.
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ]
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72491400

复制
相关文章

相似问题

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