配置步骤:
插件安装
image.png
json文件配置
- 新建文件夹并在VSCode中选择“打开”
- 添加.cpp文件和.vscode文件夹,添加
task.json
,内容如下:
{
"version": "2.0.0",
"tasks": [
{
"label": "Build with Clang",
"type": "shell",
"command": "clang++",
"args": [
"${file}",
"-std=c++11",
"-o",
"${workspaceFolder}/out/${fileBasenameNoExtension}.out",
"-g",
"--debug"
],
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: clang build active file",
"command": "/usr/bin/clang",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
- 添加
c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1",
"/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include",
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
"/Library/Developer/CommandLineTools/usr/include",
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-arm64"
}
],
"version": 4
}
其中includePath中路径可以通过终端中输入gcc -v -E -x c++ -
获得,具体参考
https://blog.csdn.net/qq_42920429/article/details/106342615
- 添加'launch.json'
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask": "C/C++: clang build active file"
}
]
}
也可以通过在debug中选择创建launch.json
文件,选择C++(GDB/LLDB)->clang
(c++则选择clang++)
image.png
image.png
或者直接在
.cpp
文件中Fn+F5
也可换出.json文件创建。
若需要运行输出在终端中显示,可以把
"externalConsole": false
替换为"externalConsole": true
参考:
>> 视频:配置过程
>> 视频:调试工具的使用
快捷键
编译运行 Control+Option+N
调试Fn+F5
调出命令窗口 Command+Shift+P
>> 所有快捷键