I apologize in advance for any spelling or grammar mistakes; I haven’t written in English in a while.
Summary of the problem
I installed the MSYS2 environment to program in C on VS Code (I dislike the online compiler provided by my uni), but I still can’t debug my code. I’m using Windows btw.
Further context
So far, I have managed to install all the C extensions in VS Code, as well as the MSYS2 environment (and I added its route to the Windows PATH).
Then, I created a folder named “C Projects” and inside it, I created both a C file named “main.c” and another folder named “.vscode”. Inside this last folder, I created two files: “launch.json” and “tasks.json”.
The “main.c” file contains simple code to test the environment:
#include <stdio.h>
int main() {
printf("Hello, World!n");
return 0;
}
Both the “launch.json” (first code) and the “tasks.json” (second code) files are meant to allow debugging in VS Code (note that I got help from ChatGPT to write this, so the mistake could be here):
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++: gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\Program Files (x86)\msys64\mingw64\bin\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build C program",
"internalConsoleOptions": "neverOpen",
"logging": { "engineLogging": true }
}
]
}
{
"version": "2.0.0",
"tasks": [
{
"label": "build C program",
"type": "shell",
"command": "C:\Program Files (x86)\msys64\mingw64\bin\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"],
"detail": "Generated task by debugging."
}
]
}
Despite having done all of this, every time I try to debug my code, I get the error “The preLaunch Task ‘build C program’ terminated with exit code -1073741819” and if I select the option “Debug Anyway”, I then get the error “launch: program ‘C:UsersiandiDownloadsC ProjectsMain.exe’ does not exist”.
If I compile the code manually in the MSYS2 terminal, I get no errors and the “Hello World” message is correctly printed, so the problem is limited to debugging in VS Code.
What could be causing this problem? Thanks in advance for the help!
ian.dib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.