前提:已经生成task.json、lunch.json、c_cpp_properties.json
插件:C/C++、CodeRunner
编译:
task.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "D:/MinGw/MinGW/bin/gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"D:\\vscode\\C\\task1.c",
"D:\\vscode\\C\\task2.c",
"-I",
"D:\\vscode\\C\\inc",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:/MinGw/MinGW/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "编译器: D:/MinGw/MinGW/bin/gcc.exe"
}
]
}
lunch.json:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:/MinGw/MinGW/bin/gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe 生成活动文件"
}
]
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
//"${workspaceFolder}/inc"
"D:/vscode/C/inc"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c99",
"cppStandard": "gnu++17",
"intelliSenseMode": "gcc-x64",
"compilerPath": "D:/MinGw/MinGW/bin/gcc.exe"
}
],
"version": 4
}
CodeRunner-->
工程结构:
调试注意事项(lunch.json):
"program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
"miDebuggerPath": "D:/MinGw/MinGW/bin/gdb.exe",
"preLaunchTask": "C/C++: gcc.exe 生成活动文件"