{ "version": "0.2.0", "configurations": [ { "name": "C/C++ Runner: Debug Session", "type": "cppdbg", "request": "launch", "args": [], "stopAtEntry": false, "externalConsole": true, "cwd": "${workspaceFolder}", // "program": "${fileDirname}/output/${fileBasenameNoExtension}.exe", "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe/build/Debug/outDebug", "MIMode": "gdb", "miDebuggerPath": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
这就是我的launch.json代码,输出文件是放在一个叫output的文件夹当中的,求求哪一位大佬帮忙挑一挑
settings.json
{ "C_Cpp_Runner.msvcBatchPath": "", "C_Cpp_Runner.cCompilerPath": "gcc", "C_Cpp_Runner.cppCompilerPath": "g++", "C_Cpp_Runner.debuggerPath": "gdb", "C_Cpp_Runner.cStandard": "", "C_Cpp_Runner.cppStandard": "", "C_Cpp_Runner.useMsvc": false, "C_Cpp_Runner.warnings": [ "-Wall", "-Wextra", "-Wpedantic", "-Wshadow", "-Wformat=2", "-Wcast-align", "-Wconversion", "-Wsign-conversion", "-Wnull-dereference" ], "C_Cpp_Runner.msvcWarnings": [ "/W4", "/permissive-", "/w14242", "/w14287", "/w14296", "/w14311", "/w14826", "/w44062", "/w44242", "/w14905", "/w14906", "/w14263", "/w44265", "/w14928" ], "C_Cpp_Runner.enableWarnings": true, "C_Cpp_Runner.warningsAsError": false, "C_Cpp_Runner.compilerArgs": [], "C_Cpp_Runner.linkerArgs": [], "C_Cpp_Runner.includePaths": [], "C_Cpp_Runner.includeSearch": [ "*", "**/*" ], "C_Cpp_Runner.excludeSearch": [ "**/build", "**/build/**", "**/.*", "**/.*/**", "**/.vscode", "**/.vscode/**" ], "C_Cpp_Runner.useAddressSanitizer": false, "C_Cpp_Runner.useUndefinedSanitizer": false, "C_Cpp_Runner.useLeakSanitizer": false, "C_Cpp_Runner.showCompilationTime": false, "C_Cpp_Runner.useLinkTimeOptimization": false, "C_Cpp_Runner.msvcSecureNoWarnings": false, "files.associations": { "iosfwd": "cpp" } }
c_cpp_properties.json
{ "configurations": [ { "name": "windows-gcc-x64", "includePath": [ "${workspaceFolder}/**" ], "compilerPath": "C:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/gcc.exe", "cStandard": "${default}", "cppStandard": "${default}", "intelliSenseMode": "windows-gcc-x64", "compilerArgs": [ "" ] } ], "version": 4 }
根据你提供的 launch.json 文件和其他配置信息,有几个地方可能需要调整或检查,以确保调试配置能够正确运行。
launch.json
你的 launch.json 中设置了程序的路径为:
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe/build/Debug/outDebug",
这里假设 ${fileBasenameNoExtension} 对应的是你的项目名称。确保以下几点:
${fileBasenameNoExtension}
outDebug
${workspaceFolder}/${fileBasenameNoExtension}.exe/build/Debug/
.exe
如果路径不正确或者文件不存在,调试器将无法启动你的程序。
在 launch.json 中,你指定了 miDebuggerPath 为 gdb,这通常是在 Linux 或者 macOS 下使用的 GDB 调试器。如果你在 Windows 上使用 MinGW 提供的 GDB,确保路径设置正确。一般来说,MinGW 的 GDB 路径类似于 C:\MinGW\bin\gdb.exe。请根据你的实际安装路径进行调整。
miDebuggerPath
gdb
C:\MinGW\bin\gdb.exe
在 settings.json 和 c_cpp_properties.json 中的配置看起来是针对 C/C++ 扩展的一些设置,确保以下几点:
C_Cpp_Runner.cCompilerPath
C_Cpp_Runner.cppCompilerPath
C_Cpp_Runner.debuggerPath
在进行任何更改后,可以尝试重新加载 Visual Studio Code 窗口,确保所有配置和扩展都能够重新加载和应用。
通过检查以上几个关键点,你应该能够找到并解决 launch.json 中的配置问题。确保路径设置正确,并且调试器能够正确识别和启动你的可执行文件。如果还遇到问题,可以查看 Visual Studio Code 的输出控制台(按 Ctrl+Shift+P,然后输入 Developer: Toggle Developer Tools 打开),查看是否有其他有用的调试信息或错误信息。
Ctrl+Shift+P
Developer: Toggle Developer Tools