MacOS下 对vs code进行C/C++配置和使用

刚入手MacBook Air,本身是个码农,花了两天时间使用vs code对C++进行配置,可以实现调试、单步调试,写此贴记录一下步骤~

  • 首先一般刚入手的mac是没有g++编译器的,先在终端里输入

g++ --version 

如果已有会提示显示版本号等信息,没有会提示你安装,点击安装即可。

  • 然后我们去官网下载vs code的macos版本,链接可以百度一下,下载完后直接将文件移动到应用里。
  • 打开vs code,选中最左边extensions,安装如下两个插件,c/c++和c/c++ clang command adapeter
  • 新建一个folder,在里面添加一个main.cpp,配置launch和tasks,
  • launch.json如下
  • {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "(lldb) Launch",
                "type": "cppdbg",
                "request": "launch",
                "program": "${workspaceFolder}/a.out",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}",
                "environment": [],
                "externalConsole": true,
                "MIMode": "lldb",
                "preLaunchTask": "build"
            }
        ]
    }

    tasks.json如下

  • {
        // See https://go.microsoft.com/fwlink/?LinkId=733558
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "shell",
                "command": "g++",
                "args": [
                    "-g",
                    "main.cpp"
                ],
                "group": {
                    "kind":"build",
                    "isDefault": true
                }
            }
        ]
    }

     

 

  1.  

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值