user6374460
user6374460

Reputation:

C++ for VS code: Unable to start debugging - Program path is missing or invalid

Unable to start debugging. Program path '/home/student/Documents/Visual Studio Code/rectangle' is missing or invalid.

My launch.json looks like this:

{

    "version": "0.2.0",
    "configurations": [

        {
            "name": "C++ Launch (GDB)",
            "type": "cppdbg",
            "request": "launch",
            "launchOptionType": "Local",
            "miDebuggerPath": "/usr/bin/gdb",
            "targetArchitecture": "x64",
            "program": "${workspaceRoot}/rectangle",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": []
        },
        {
            "name": "C++ Attach (GDB)",
            "type": "cppdbg",
            "request": "launch",
            "launchOptionType": "Local",
            "miDebuggerPath": "/usr/bin/gdb",
            "targetArchitecture": "x64",
            "program": "${workspaceRoot}/rectangle",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": []
        }
    ]
}

My C++ program is this:

#include <iostream>
using namespace std;

int main()

{

    double length, width, area;

    cout << "Enter the length: ";
    cin >> length;
    cout << "Enter the width: ";
    cin >> width;
    area = length * width;
    cout << "The area is " << area << endl;
    return 0;

}

Upvotes: -1

Views: 23387

Answers (2)

eatcosmos
eatcosmos

Reputation: 11

Are you install Cygwin and minGW at the same time or just install Cygwin?
In any above two case, please make sure that VSCODE call g++ and gdb of minGW, you can just add bin path of minGW and remove bin path of Cygwin from system environment. Because exe build by Cygwin rely on cygwin1.dll which is not the pure win exe, so gdb can't do with this exe well.

Upvotes: 1

Frank T
Frank T

Reputation: 126

Is the "rectangle" file your C++ source code mentioned above?

If so, it should - by convention - be renamed to "rectangle.cpp" and then compiled into a binary/runnable program - which could be named "rectangle".

To my knowledge, you must use a compiler external to VSCODE, but can set up a build task (and a file watcher and a problem matcher if you're feeling advanced) that automates the compile proces.

Upvotes: 2

Related Questions