用于VS代码的C ++:无法启动调试 - 程序路径丢失或无效

时间:2016-05-24 06:32:06

标签: c++ json visual-studio-code

无法开始调试。程序路径' / home / student / Documents / Visual Studio代码/矩形'缺失或无效。

我的launch.json看起来像这样:

{

    "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": []
        }
    ]
}

我的C ++程序是这样的:

#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 个答案:

答案 0 :(得分:1)

是&#34;矩形&#34;提交上面提到的C ++源代码?

如果是这样,按照惯例,它应该重命名为&#34; rectangle.cpp&#34;然后编译成二进制/可运行程序 - 可以命名为&#34;矩形&#34;。

据我所知,你必须使用VSCODE外部的编译器,但是可以设置一个构建任务(以及一个文件观察器和一个问题匹配器,如果你感觉很高级),它可以自动化编译过程。

答案 1 :(得分:0)

您是同时安装Cygwin和minGW还是只安装Cygwin?
在上述两种情况下,请确保VSCODE调用minGW的g ++和gdb,你只需添加minGW的bin路径并从系统环境中删除Cygwin的bin路径。 因为Cygwin构建的exe依赖于cygwin1.dll而不是纯粹的win exe,所以gdb不能很好地处理这个exe。