針對調試C語言時一閃而過解決辦法
前提:
已經按照 C/C++
已經安裝 MINGW(並配置完成)
原因:
主要是因為tasks的配置沒有寫對
解決辦法:
tasks.json
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "command": "gcc", //gcc 編譯條件 //gcc gdb-sample.c -o gdb-sample -g "args": [ "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}", "-g", ], }
最主要的就是args這個參數了
配合GCC編譯調試條件填寫即可
gcc gdb-sample.c -o gdb-sample -g
gcc="command": "gcc"
gdb-sample.c=源文件 也就是 "${file}"
-o=編譯條件
gdb-sample="生成文件",可以寫成"${fileDirname}/${fileBasenameNoExtension}",
-g=調試條件
Launch.json
{ // 使用 IntelliSense 了解相關屬性。 // 懸停以查看現有屬性的描述。 // 欲了解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "targetArchitecture": "x64", "program": "${fileDirname}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "gcc" } ] }
launch最主要就是兩個
miDebugggerPath=這個是gdb所在的位置,仔細填寫即可
program=這個則是調試可運行程序所在的位置。
對於具體的vscode的條件編寫可以參考https://code.visualstudio.com/docs/editor/variables-reference【可配合谷歌瀏覽器實時翻譯】

