刚入手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 } } ] }