编译器下载
x86_64-posix-seh
或其他的编译器。D:\vscodeCompile
文件夹下。D:\vscodeCompile\mingw64\bin
目录写入高级系统设置
中的环境变量中。配置VS code
#include
using namespace std;
int main()
{
cout << "hello" << endl;
return 0;
}
.vscode/tasks.json
文件。args
和group
两个变量的值点击下方工具条上的Debug
符号。
依次点击“添加配置”–>“C++(GDB/LLDB)”,以及目标编译器。
Ctrl+Shift+b
一键生成,按F5
执行程序。"preLaunchTask": "buildsource",
配置项,可以在F5调试之前运行task.json中的编译任务,这样就不用先一键生成了。{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"preLaunchTask": "buildsource",
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
{
"tasks": [
{
"type": "cppbuild",
"label": "buildsource",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-Wfatal-errors",
"-Wall"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}