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

相关推荐
程序员小寒2 小时前
VSCode有哪些好用的插件和快捷键?
ide·vscode·编辑器
Mac技巧大咖3 小时前
Mac误删文件,废纸篓也清了?Mac时光机器仍可恢复找回
macos·mac误删文件
程序员果子4 小时前
零拷贝:程序性能加速的终极奥秘
linux·运维·nginx·macos·缓存·centos
天庭鸡腿哥5 小时前
macOS的功能,在Windows上也能实现
windows·microsoft·macos·visual studio·everything
Byron Loong5 小时前
【Debug】vscode 调试python,如何配置固定调试文件
ide·vscode·python
weixin_462446235 小时前
macOS 安装 git-lfs
git·macos
电子_咸鱼5 小时前
【QT SDK 下载安装步骤详解 + QT Creator 导航栏使用教程】
服务器·开发语言·网络·windows·vscode·qt·visual studio code
HealthScience8 小时前
vscode通过跳板机连接到服务器
服务器·ide·vscode
猿小猴子10 小时前
主流 AI IDE 之一的 Kiro 介绍
ide·ai·kiro
神码小Z10 小时前
为什么架构师岗位即将消失?学会使用Cursor的三大神器Rules、Memories、Commands!小白也能写出专家级代码!
ide·intellij-idea