配置环境:Macbook Pro操作系统MacOS Catalina 10.15.4.
首先在浏览器中搜索vscode,打开搜索结果第一条,然后点击“Download for Mac”然后在页面停留一会就下载了vscode安装程序
解压缩,
将文件拉入应用程序即可。
安装插件C\C++,C\C++ Clang Command Adapter,CodeLLDB(用来debug,解决Catalina不支持lldb调试问题)以及code runner(用来编译)。
添加配置文件:tasks.json、launch.json、以及c_cpp_properties.json.
shift+command+P点击C/C++ 编辑配置(JSON),出现文件c_cpp_properties.json,
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
{
"version": "2.0.0",
"tasks": [
{
"label": "Build with Clang",
"type": "shell",
"command": "clang++",
"args": [
"${file}",
"-std=c++11",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.out",
"-g",
"--debug"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
{
// 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": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${fileDirname}/${fileBasenameNoExtension}.out",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
#include
int main()
{
for(int i=0;i<5;i++){
std::cout<<"hey you"<
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
将之前的launch.json文件删除,添加lldb 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": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${fileDirname}/${fileBasenameNoExtension}.out",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
设置断点:点击运行,按F5错误消失,并且按照每一步输出结果:
另外需要注意的一点:如果更改了程序的内容,保存之后,需要重新shift+command+B,产生新的.out文件,这样再按F5调试才是修改后的结果,否则仍然是修改前的结果。
参考链接:
https://www.bilibili.com/video/BV1U741157Rd/?p=2&t=40
https://www.bilibili.com/video/BV1z7411N7Pg?from=search&seid=13295932737773533081
希望对大家有帮助。