Mac-VScode

1) 安装 xcode。

打开App Store,搜索xcode,进行下载安装。

2)执行命令:

xcode-select --install

3)安装VS Code

https://code.visualstudio.com/

4) 打开vs code。打开左侧扩展栏,安装c++扩展

5)c_cpp_properties.json文件

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/Library/Developer/CommandLineTools/usr/include/c++/v1",
            "/usr/local/include",
            "/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include",
            "/Library/Developer/CommandLineTools/usr/include",
            "/usr/include"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

6)配置task.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "c++",
            "command": "clang++",
            "type": "shell",
            "args": [
                "./c++/hello.cpp",//根据需要修改
                "-std=c++11",
                "-g"
            ],
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            }
        }
    ]
}

7)配置launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "c/c++ Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/a.out",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "lldb",
        "preLaunchTask":"c++"
        }
    ]
}

8)开启调试

扫描二维码关注公众号,回复: 7732221 查看本文章

参考:https://www.cnblogs.com/xuanhun/p/9890931.html

猜你喜欢

转载自www.cnblogs.com/yrm1160029237/p/11787765.html