在macOS上配置Visual Studio 以使用Clang/LLVM编译器和调试器
一.Needed extension:
C/C++
C/C++ Extension Pack
clang
CodeLLDB
CodeLLDB首次启动时自动安装codelldb-x86_64-darwin.vsix(访问外网)
请等待它安装完成,安装失败将无法调试
二.Add configuration of C++
- 第一次运行c++程序时,C++扩展将创建tasks.json
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
三.Add configuration of debug
点击调试图标后进行设置
- 第一次点开将提示添加配置,VS Code将创建一个launch.json文件
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++: clang++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C++: clang++ build active file"
}
]
}