VSCode MAC CPP运行环境配置

使用vscode运行cpp确实挺麻烦的,需要配置几个文件,简单来说:

  • c_cpp_properties.json 用来配置编译器和编译选项
  • launch.json 用来配置运行时选项
  • tasks.json 用来配置debug选项

.vscode/c_cpp_properties.json

bash 复制代码
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang++",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-x64"
        }
    ],
    "version": 4
}

.vscode/launch.json

bash 复制代码
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "mydb",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "Build with Clang"
        }
    ]
  }
  

注意type改成lldb,program选项填生成的可执行文件,cwd选项填当前工作路径,preLaunchTask选项填写tasks.json的label。

.vscode/tasks.json

cpp 复制代码
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build with Clang",
            "type": "shell",
            "command": "clang++",
            "args": [
                "-std=c++17",
                "-stdlib=libc++",
				"-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "--debug"
            ],
            "group": "build"
        },
    
    ]
}

注意label选项,type应该无所谓,args要填对,-g是要编译的文件,-o是编译输出文件名。

相关推荐
golang学习记7 小时前
IDEA 2026年的玩法已经完全不同
java·ide·intellij-idea
纪伊路上盛名在14 小时前
windows 配置vscode x11转发
ide·vscode·编辑器
Web3&Basketball16 小时前
Meta Muse 816B 实测:两台 Mac 本地跑通
macos·大模型·mac·本地部署·moe·显存优化·meta muse
DevLoom_17 小时前
macOS 27 升级翻车怎么降级?不用终端,2 种方案实测回退旧系统
macos·macos27·mac系统降级·macos安装盘·mac使用技巧
comedate17 小时前
Cursor 和 GitHub Copilot 怎么选?2026 年 AI 编程助手对比
ide·ai编程·cursor·github copilot
2501_9151063220 小时前
KXApp 的 VS Code 真机调试:按下 Cmd+R 之后发生了什么
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
hkj880820 小时前
VsCode的使用
ide·vscode·编辑器
向着光芒的女孩1 天前
【Mac】腾讯视频会议在Mac电脑屏幕共享失败解决方案
macos
あ-2 天前
mac dbeaver安装后显示数据包损坏
macos
钱栈up2 天前
从 macOS 切回 Windows,我用 5 个免费工具把 80% 操作习惯搬了回来
windows·macos·策略模式