Home > Blockchain >  Setting up VS Code for C using Cygwin64 Compiler and Debugger on Windows (ERROR: Unable to start deb
Setting up VS Code for C using Cygwin64 Compiler and Debugger on Windows (ERROR: Unable to start deb

Time:10-29

I am trying to set up VSCODE to debug a C program on Windows using Cygwin64.

I used the config suggested by @stephw ( Cygwin Setup window and the current gdb version installed.

I changed my launch.json just a little bit. Notice the "preLaunchTask" key does not have the exact same value that the "label" key in the tasks.json has:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [
                {
                    "name": "PATH",
                    "value": "%PATH%;C:\\cygwin64\\bin"
                }
            ],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\cygwin64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "logging": { "engineLogging": true }, //optional
            "preLaunchTask": "gcc.exe build active file"
        }
    ]
}

My tasks.json is this (notice my name in the end, in the "detail" key):

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C  : gcc.exe build active file",
            "command": "C:\\cygwin64\\bin\\gcc.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "Task generated by Leonardo."
        }
    ]
}

I notice something a little bit strange: When I press F5, it does not work, because the task created is not found.

Dialog saying the task was not found.

When I edited my launch.json file (preLaunchTask key) to the exact same value in the tasks.json file, the "not found" error disappears, but the debugging process does not start.

"preLaunchTask": "C/C  : gcc.exe build active file"

If I press the Run and debug play button, the debug process does not work either.

Visual Studio Code Run and debug play button.

When I use the Command Palette (pressing CTRL SHIFT P), and click C/C : Build and Debug Active File,

Visual Studio Code Command Palette...

and then choose the task I created (the second one appears to be automatic), A list of the tasks available to execute.

the program is compiled and the debug process is started.

This is my very simple test script:

#include <stdio.h>
#include <stdlib.h>

int main() {

    /* declare and initialize string */
    char myString[] = "This is an example of string declaration!";

    /* print string */
    printf("%s", myString);

    int numberA = 5;
    int numberB = 10;

    int sum = numberA   numberB;

    /* Printing a number */
    printf("A soma de numberA   numberB é: %d", sum);

    return 0;
}

I hope this question and answer can help someone in the future. Peace.

  • Related