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

相关推荐
飞翔的SA1 小时前
MLX‑VLM :Mac本地跑通多模态大模型的开源项目!让图片、音频、视频理解一键上手
人工智能·python·macos·音视频
sunfdf15 小时前
移动硬盘上的文件消失了?以下是Mac电脑解决方法
macos·电脑
Freak嵌入式15 小时前
ESP32 实现在线动态安装库和自动依赖安装-使用uPyPI包管理平台
arm开发·ide·嵌入式·micropython·电子·upypi
偶尔贪玩的骑士18 小时前
Jupyter Notebook导出带中文字体PDF
ide·jupyter·pdf
秃秃然然18 小时前
IntelliJ IDEA指北
java·ide·intellij-idea
70asunflower18 小时前
VS Code 从 0 到 1 完全教程
vscode
鱼骨不是鱼翅21 小时前
jupyter notebook
ide·人工智能·jupyter
程序设计实验室1 天前
浅谈次世代代码编辑器 Zed:Rust 原生性能、GPU 渲染
ide
李子焱1 天前
第三节:开发环境搭建与Trae IDE深度配置
前端·ide·python·node.js·trae ide
蜗牛 Day Day Up1 天前
vscode运行TypeScript
ide·vscode·typescript