-1

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;

}
2
  • You provided us with a lot of info, but... What about program path '/home/student/Documents/Visual Studio Code/rectangle' being missing or invalid? Can you verify such path exists? :-) Commented May 24, 2016 at 6:36
  • Yes, look at the "print working directory" result of my path:[student@rhel7 Visual Studio Code]$ pwd /home/student/Documents/Visual Studio Code [student@rhel7 Visual Studio Code]$ ls -l rectangle -rw-rw-r--. 1 student student 287 May 24 13:27 rectangle Commented May 24, 2016 at 18:29

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I changed the name to rectangle.cpp and used cpp to compile it. Then I opened it in VS. I tried >Run and >Run Build Task, but can't get it to run. Is the compile command: "cpp rectangle.cpp -o rectangle" all I need to do? What I suspect is that my launch.json file is not configured correctly. Can you take a look at my first post and recommend how to configure it if that's needed?
The compile command looks OK - unsure about how much debug info is generated, but for running it looks as the minimum required. I believe the json file for the Run command (task) is different from the one used for debugging. Could you show your "tasks.json" file?
Thanks(!) everyone, but I'm scrapping VS code because I just found 2 superior programs on Redhat for C++ (Anjuta and CodeBlocks) :)
Try writing the whole path to rectangle in your 'program' parameter. Don't use ${workspaceRoot}. This worked for me
1

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.

Comments