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是编译输出文件名。

相关推荐
小庞在加油5 小时前
从qmake到CMake+VSCode:Qt项目现代化迁移与AI提效实战指南
vscode·qt·ai·ai工具
utf8mb4安全女神6 小时前
HTML网页【vscode】【Linux】
ide·vscode·编辑器
S-码农9 小时前
vscode 通过 SSH 远程控制 Ubuntu
vscode·ubuntu·ssh
星栈独行10 小时前
Rust + Makepad 应用怎么打包发布:Windows、macOS、Linux 全平台交付
windows·程序人生·macos·ui·rust
daly52010 小时前
PyCharm怎么下载?2026最新版PyCharm安装教程(Windows/macOS/Linux)
windows·macos·pycharm
元媛媛11 小时前
如何安装Claude Code|VS Code Mac版
macos
A.说学逗唱的Coke11 小时前
【大模型专题】AI Copilot 完整实践指南:VSCode + GitHub Copilot Agent 模式全攻略
人工智能·vscode·copilot
2601_961845421 天前
法考真题及答案解析|历年真题|资料已整理
linux·windows·ubuntu·macos·centos·gnu
嵌入式小站1 天前
STM32 可移植教程 02:按键状态机,消抖、长按、释放一行也不用多写(实战篇)
chrome·vscode·stm32·单片机·嵌入式硬件