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

相关推荐
音草27 分钟前
C++ 继承详解:从概念到菱形继承
c++
weixin_3077791337 分钟前
C++代码实现MATLAB中的spectralcluster函数功能
开发语言·c++·算法·matlab
一条泥憨鱼1 小时前
【计算机网络】| 从 MAC 到 NAT 的跨网段通信全链路
服务器·网络·学习·计算机网络·macos
xiaoye-duck1 小时前
《C++ 项目:手写大模型接入 SDK》Trae IDE 开发环境搭建与依赖管理
c++·ide·语言模型
沫璃染墨2 小时前
《Qt从零入门系列(十四):QThread多线程详解——从线程创建到客户端阻塞处理》
开发语言·c++·笔记·qt·ui·交互·线程
草莓熊Lotso2 小时前
【C++ 基于微服务的即时通讯系统】Elasticsearch 从安装到 C++ 客户端二次封装全落地
linux·网络·数据库·c++·elasticsearch·微服务
CHPCWWHSU2 小时前
FreeCAD 源码解读:从 Property 到 Command,看一套 CAD 内核的完整闭环
c++·cad
代钦塔拉2 小时前
【C++/Qt 进阶】设计模式系列(5):适配器模式——给“不兼容的接口“贴一层翻译膜
c++·qt·设计模式
aqiu1111112 小时前
蓝桥杯真题复盘:Fibonacci 数列与黄金分割(C++ 算法详解)
c++·算法·蓝桥杯
lojox2 小时前
C++ 手写 STL list(双向循环链表)原理剖析与实现
c++·链表·list