VSCode的launch配置
用VsCode调试C++代码出现如下情况,在网上找了多个答案均无法解决问题tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:\\lenovo_edge\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-fexec-charset=GBK"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
launch.json
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\lenovo_edge\\mingw64\\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++: g++.exe 生成活动文件"
}
]
}
根据你提供的launch配置,存在两个问题可能导致无法成功调试C++代码:
1. 任务(task)配置:在你的tasks.json文件中,调试任务的命令D:\\lenovo_edge\\mingw64\\bin\\g++.exe没有指定具体的源代码文件路径 ${file},这可能导致编译器无法找到要编译的源文件。
2. 调试器(debugger)配置:在你的launch.json文件中,调试器的program属性指定了可执行文件的路径${fileDirname}\\${fileBasenameNoExtension}.exe,但是在任务中的编译输出路径是${fileDirname}\\${fileBasenameNoExtension}.exe,这样会导致调试器无法找到正确的可执行文件。
下面是修改后的tasks.json和launch.json文件配置示例:
tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:\\lenovo_edge\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-fexec-charset=GBK"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\lenovo_edge\\mingw64\\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++: g++.exe 生成活动文件"
}
]
}
请注意,以上示例假设g++.exe和gdb.exe都位于D:\\lenovo_edge\\mingw64\\bin目录中。
你可以根据这个示例修改你的配置文件,确保任务和调试器的配置正确,然后尝试重新调试C++代码。
希望这能解决你的问题!如果还有其他疑问,请随时提问。 所以你是出现了什么情况? 陶远航 发表于 2023-7-15 19:19
根据你提供的launch配置,存在两个问题可能导致无法成功调试C++代码:
1. 任务(task)配置:在你的tasks. ...
您好,这个示例我没看懂,请问是如何修改路径 isdkz 发表于 2023-7-15 19:20
所以你是出现了什么情况?
launch:program'源代码文件路径' does ont exist
页:
[1]