avatar

Mac环境下Vscode的C++配置

本文主要针对于debug进行说明

第一次运行C语言

这个都没什么好说的,Vscode for mac安装后在插件处安装C++,为了更好的运行,安装CodeRunner插件就可以

image-20200302103150551

⌘+, 打开Settings,我个人是比较喜欢清除之前记录,当然为了对比你也可以不勾选。

此时的话运行应该是不成问题的。

进行Debug调试

这之前在插件里安装CodeLLDB哦

时间稍微有点长,耐心等待

  1. ⇧⌘P搜索Edit Configurations(JSON),在c_cpp_properties.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/Library/Developer/CommandLineTools/usr/include/c++/v1",
"/usr/local/include",
"/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include",
"/Library/Developer/CommandLineTools/usr/include",
"/usr/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1"
],
"defines": [],
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}

cp就行,问题不大,前提是Xcode安装了命令行的工具(一般都是完全安装吧)

  1. ⇧⌘P搜索Tasks选择C++,在tasks.json中cp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "c++",
"command": "clang++",
"type": "shell",
"args": [
"${file}",
"-std=c++11",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.out",
"-g",
"--debug"
],
"group": {
"kind": "build",
"isDefault": true
}
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
}
]
}
  1. 在左侧工具栏
image-20200302103941471

选择后再次cp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
// 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) 启动",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.out",
"args": [],
"cwd": "${workspaceFolder}"
}

]
}
  1. 至此我们就完成了 如果出现报错Internal debugger error: unable to find executable for ‘PATH/xxx.out’,先⇧⌘B编译一下就好了

    BTY

    可以设置一下代码格式规范,随意选择一个cpp文件,shift + option + F,选择一个标准,然后在设置里搜索image-20200302104733857

就会随时格式化了

image-20200302104956062

感觉还是不错的,theme是Mix One Dark 2,字体FiraCode

顺带一提,由于CodeRunner编译是编译现有文件,所以会比自动保存稍微快一点,如果运行不成功多按几次一两秒就可以了

文章作者: X Mεl0n
文章链接: http://www.zrzz.site/2020/03/02/Mac%E7%8E%AF%E5%A2%83%E4%B8%8BVscode%E7%9A%84C-%E9%85%8D%E7%BD%AE/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 X Mεl0n | 随手记

评论