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

相关推荐
azoo1 小时前
jupyter notebook 无法启动- markupsafe导致
ide·人工智能·jupyter
小豹子的技术笔记1 小时前
使用 IntelliJ IDEA 进行远程调试
java·ide·intellij-idea
友善的猴子3 小时前
AlDente Pro for Mac电脑 充电限制保护工具
macos·电脑
世界尽头与你4 小时前
MacOS红队常用攻击命令
安全·macos·网络安全
干净的坏蛋6 小时前
mac 终端 code 命令打开 vscode,修改 cursor占用
ide·vscode·macos
石头wang6 小时前
如何关闭MacOS中鼠标滚轮滚动加速
macos·滚轮滚动加速
扰动欧几里得空间6 小时前
通过Arduino IDE向闪存文件系统上传文件
ide
小狗爱吃黄桃罐头8 小时前
同时打开多个Microchip MPLAB X IDE
ide·microchip·maplab x ide
我劳动我光荣11 小时前
【ESP32-microros(vscode-Platformio)】
ide·vscode·编辑器
柯基的小屁墩11 小时前
mac|使用scrcpy实现无线Android投屏
macos