I want to use Vscode to debug the code. I checked a lot of environment configuration information on the Internet, but I don’t know why this problem always occurs: After
researching for a long time, I finally found a violent solution to this problem. I will record it here.
1. Generate tasks.json file
Shortcut key Ctrl+Shift+P, find it Tasks: Configuration Default Build Task
, the following window will pop up:
Here select the location where gcc is used on the computer, here is C:/MinGW/bin/gcc.exe, and
then the tasks.json file will be generated
on my computer. Each parameter of the generated file above is as follows:
After testing, it was found that "type" must be modified to "shell"
. I did not delve into why it was modified in this way. At least under "cppbuild"
this parameter, debugging will cause the error shown at the beginning.
2. Generate launch.json
The process of generating launch.json is also very strange.
First, select Add Configuration in Run, and select C++ (GDB/LLDB) in the pop-up window.
Launch.json will indeed be generated at this time, but the file is empty and must be repeated again. In the just operation, after selecting C++ (GDB/LLDB), a new window will pop up.
In this window, select C/C++: (gdb) Launch.
The launch.json generated at this time is like this:
Next, you need to ”program“
modify it to ${fileDirname}/${fileBasenameNoExtension}.exe
, and then "miDebuggerPath"
Corresponding to the path to gdb, finally add a line at the end: "preLaunchTask": "C/C++: gcc.exe build active file"
, preLaunchTask
the content here needs to label
be consistent with the content in tasks.json.
After the modification is completed, it will look like this:
After completing the above tasks, you can successfully debug C code.