Mac-VScode-C++环境配置

mac上自带了clang所以不是必须下载Homebrew

下面是配置文件(注释记得删一下)

package.json

复制代码
{
    "name": "git-base",
    "displayName": "%displayName%",
    "description": "%description%",
    "version": "1.0.0",
    "publisher": "vscode",
    "license": "MIT",
    "engines": {
        "vscode": "0.10.x"
    },
    "categories": ["Other"],
    "main": "./dist/extension.js",
    "browser": "./dist/browser/extension.js",
    "icon": "resources/icons/git.png",
    "capabilities": {
        "virtualWorkspaces": true,
        "untrustedWorkspaces": {
            "supported": true
        }
    },
    "contributes": {
        "commands": [
            {
                "command": "git-base.api.getRemoteSources",
                "title": "%command.api.getRemoteSources%",
                "category": "Git Base API"
            }
        ],
        "menus": {
            "commandPalette": [
                {
                    "command": "git-base.api.getRemoteSources",
                    "when": "false"
                }
            ]
        },
        "languages": [
            {
                "id": "git-commit",
                "aliases": ["Git Commit Message", "git-commit"],
                "filenames": ["COMMIT_EDITMSG", "MERGE_MSG"],
                "configuration": "./languages/git-commit.language-configuration.json"
            },
            {
                "id": "git-rebase",
                "aliases": ["Git Rebase Message", "git-rebase"],
                "filenames": ["git-rebase-todo"],
                "filenamePatterns": ["**/rebase-merge/done"],
                "configuration": "./languages/git-rebase.language-configuration.json"
            },
            {
                "id": "ignore",
                "aliases": ["Ignore", "ignore"],
                "extensions": [".gitignore_global", ".gitignore", ".git-blame-ignore-revs"],
                "configuration": "./languages/ignore.language-configuration.json"
            }
        ],
        "grammars": [
            {
                "language": "git-commit",
                "scopeName": "text.git-commit",
                "path": "./syntaxes/git-commit.tmLanguage.json"
            },
            {
                "language": "git-rebase",
                "scopeName": "text.git-rebase",
                "path": "./syntaxes/git-rebase.tmLanguage.json"
            },
            {
                "language": "ignore",
                "scopeName": "source.ignore",
                "path": "./syntaxes/ignore.tmLanguage.json"
            }
        ]
    },
    "repository": {
        "type": "git",
        "url": "https://github.com/microsoft/vscode.git"
    }
}

c_cpp_propreties.json

复制代码
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"  // 指定 libc++ 路径
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang++",  // 使用 clang++ 编译器
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-arm64"
        }
    ],
    "version": 4
}

settings.json

复制代码
{
    "code-runner.executorMap": {
        "cpp": "cd $dir && clang++ -std=c++17 -stdlib=libc++ -Wall $fileName -o a.out && ./a.out"  // 使用 clang++ 编译器
    },
    "code-runner.runInTerminal": true,
    "files.autoSave": "afterDelay",
    "terminal.integrated.defaultProfile.osx": "zsh",
    "terminal.integrated.defaultEncoding": "utf-8",
    "locale": "zh-cn",
    "enable-crash-reporter": true,
    "crash-reporter-id": "3205589b-8611-4466-8315-38f465957f48"
}

其中 code-runner.runInTerminal设置为true解决了mac默认在输出跑无法输入的问题

tasks.json

复制代码
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "C/C++: clang++ 生成活动文件",
            "type": "shell",
            "command": "/usr/bin/clang++",  // 使用 clang++ 编译器
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": "build",
            "problemMatcher": [
                "$gcc"  // 使用 $gcc 而不是 $clang
            ],
            "detail": "生成 C++ 程序"
        },
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ 生成活动文件",
            "command": "/usr/bin/clang++",  // 使用 clang++ 编译器
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"  // 使用 $gcc 而不是 $clang
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ]
}

C/C++编辑配置(UI)

command+shift+p,输入C/C++编辑配置(UI)

编辑器路径:/usr/bin/clang++

IntelliSense 模式根据你的芯片选择是arm还是intell

c标准的话一般为17

相关推荐
hjjdebug1 小时前
constexpr 关键字的意义(入门)
c++·constexpr
虾球xz2 小时前
游戏引擎学习第282天:Z轴移动与摄像机运动
c++·学习·游戏引擎
.小墨迹3 小时前
Apollo学习——planning模块(3)之planning_base
linux·开发语言·c++·学习·自动驾驶
龙湾开发3 小时前
计算机图形学编程(使用OpenGL和C++)(第2版)学习笔记 10.增强表面细节(一)过程式凹凸贴图
c++·笔记·学习·3d·图形渲染
德亦周3 小时前
如何在Mac电脑上的VScode去配置C/C++环境
c++·vscode·macos
XiaoyaoCarter3 小时前
每日一道leetcode(新学数据结构版)
数据结构·c++·算法·leetcode·职场和发展·哈希算法·前缀树
八月的雨季 最後的冰吻4 小时前
SIP协议栈--osip源码梳理
linux·服务器·网络·c++·网络协议
fancy1661664 小时前
搜索二维矩阵 II
c++·算法·矩阵
freyazzr4 小时前
Leetcode刷题 | Day63_图论08_拓扑排序
数据结构·c++·算法·leetcode·图论
顾子茵5 小时前
c++从入门到精通(四)--动态内存,模板与泛型编程
java·开发语言·c++