一、launch.json
{
"version" : "0.2.0" ,
"configurations" : [
{
"name" : "gcc.exe - 生成和调试活动文件" ,
"type" : "cppdbg" ,
"request" : "launch" ,
"program" : "${fileDirname}\\${fileBasenameNoExtension}.exe" ,
"args" : [ ] ,
"stopAtEntry" : false ,
"cwd" : "${workspaceFolder}" ,
"environment" : [ ] ,
"externalConsole" : true ,
"MIMode" : "gdb" ,
"miDebuggerPath" : "C:\\mingw64\\bin\\gdb.exe" ,
"setupCommands" : [
{
"description" : "为 gdb 启用整齐打印" ,
"text" : "-enable-pretty-printing" ,
"ignoreFailures" : true
}
] ,
"preLaunchTask" : "C/C++: gcc.exe build active file"
}
]
}
修改为"externalConsole": false
时,采用集成终端调试。 采用外部终端调试时,修改以下两项可避免终端闪退:
"program" : "C:\\Windows\\system32\\cmd.exe"
"args" : [ "/C" , "${fileDirname}\\${fileBasenameNoExtension}.exe" , "&" , "pause" ]
二、tasks.json
{
"version" : "2.0.0" ,
"tasks" : [
{
"type" : "shell" ,
"label" : "C/C++: gcc.exe build active file" ,
"command" : "C:\\mingw64\\bin\\gcc.exe" ,
"args" : [
"-g" ,
"${file}" ,
"-o" ,
"${fileDirname}\\${fileBasenameNoExtension}.exe"
] ,
"options" : {
"cwd" : "${workspaceFolder}"
} ,
"problemMatcher" : [
"$gcc"
] ,
"group" : {
"kind" : "build" ,
"isDefault" : true
}
}
]
}
三、c_cpp_properties.json
{
"configurations" : [
{
"name" : "Win32" ,
"includePath" : [
"${workspaceFolder}/**"
] ,
"defines" : [
"_DEBUG" ,
"UNICODE" ,
"_UNICODE"
] ,
"compilerPath" : "C:\\mingw64\\bin\\gcc.exe" ,
"cStandard" : "c99" ,
"cppStandard" : "gnu++14" ,
"intelliSenseMode" : "gcc-x64"
}
] ,
"version" : 4
}
"cStandard"的可选值: “c89”, “c99”, “c11”, “c17”, “gnu89”, “gnu99”, “gnu11”, “gnu17”, “${default}”。 "cppStandard"的可选值: “c++98”, “c++03”, “c++11”, “c++14”, “c++17”, “c++20”, “gnu++98”, “gnu++03”, “gnu++11”, “gnu++14”, “gnu++17”, “gnu++20”, “${default}”。
参考:
vscode配置C调试环境(launch.json tasks.json setting.json) 绝对好使!VSCode for Mac调试C/C++配置lauch.json和tasks.json 40 VSCode下.json文件的编写——(1) linux/g++ (2).json中参数与预定义变量的意义解释