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

相关推荐
一块小土坷垃1 小时前
# AutoCAD 2027 专业级CAD设计绘图软件核心解析与使用评价
macos·开源软件
郝学胜-神的一滴4 小时前
Qt 高级开发 005: Qt Creator与Visual Studio 项目双向转换
开发语言·c++·ide·qt·程序人生·visual studio
不剪发的Tony老师7 小时前
Code::Blocks:一款免费开源的C/C++/Fortran集成开发环境
c语言·c++·ide
高斯林.神犇7 小时前
Idea中使用Git
java·ide·intellij-idea
Rudon滨海渔村11 小时前
MacBookPro更换硬盘-重新安装macOS+Win10LTSC双系统-官方免费工具
macos
lifewange11 小时前
如何在VScode中配置shell环境?
ide·vscode·编辑器
codingxb4511 小时前
VSCode中使用ClaudeCode接入Deepseek-v4模型
vscode·deepseek·claude code
一块小土坷垃11 小时前
# ArchiCAD 29.0.2(畅享版):专为建筑师打造的BIM高效建模工具
前端·数据库·macos·开源软件
代码讲故事11 小时前
mac电脑上docker突然无法运行,不停的出现弹框,“com.docker.vmnetd”将对你的电脑造成伤害。附国内不同芯片高速下载地址,下载直接运行。
macos·docker·容器·arm·mac·intel·下载
lpfasd12311 小时前
Trae Solo 与 Qoder Quest
ide·人工智能·cli