鉴于网上教程可用性不高,为此写下教程.
此教程适合于广大Mac(全平台)用户, Windows用户可选宇宙无敌的VS.(划掉)
(更新) Windows试用llvm和gdb实现调试.
tva2.sinaimg.cn/large/006tNc79ly1fzhypwaw8jj311e0u0hbh.jpg)
Shell
1Xcode command tools
2vsc
3Cpptools
COPY
终端键入
bash
1xcode-select --install
COPY
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/Debug/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"preLaunchTask": "build",
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
// "miDebuggerPath": "/etc/bin",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "clang++",
"type": "shell",
"args": [
"-g","-o","Debug/${fileBasenameNoExtension}.out","${file}",
"-std=c++11",
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
}
],
}
,在网页中找到适用于Windows 64位的最新预编译版本,不需要下载sig签名文件。安装过程中注意选择为所有用户安装,这样会为你添加到环境变量。 这两步完成以后打开cmd,输入clang应该可以看到如下输出。
MinGW-w64 - for 32 and 64 bit Windows
,安装时注意选择体系架构为x86_64。由于网络原因,你可能不能把它下载下来,经过一点探索,安装程序需要下载一个叫做x86_64-7.1.0-release-posix-seh-rt_v5-rev2
的文件,其实我们可以直接在SourceForge上搜到这个
MinGW-w64 - for 32 and 64 bit Windows
,到里面选择第一个下载。下载完成后解压里面的mingw64文件夹中的内容到你安装LLVM的同一个目录合并,合并里面所有文件夹,不会有冲突。
打开终端验证是否能够打开gdb.exe.
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch in Windows",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"preLaunchTask": "BuildInWindows",
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
]
},
]
}
json
1{
2 "version": "2.0.0",
3 "tasks": [
4
5 {
6 "label": "BuildInWindows",
7 "command": "clang++",
8 "type": "shell",
9 "args": [
10 "-g","-o","${fileBasenameNoExtension}.exe","${file}",
11 "-std=c++11",
12
13 ],
14 "presentation": {
15 "echo": true,
16 "reveal": "always",
17 "focus": false,
18 "panel": "shared"
19 }
20 }
21 ],
22}
COPY
最后成功调试!