2016-05-24 104 views
1

无法启动调试。程序路径'/ home/student/Documents/Visual Studio Code/rectangle'缺失或无效。VS代码的C++:无法启动调试 - 程序路径丢失或无效

我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; 

} 
+0

您向我们提供了很多信息,但是......程序路径“/ home/student/Documents/Visual Studio代码/矩形”丢失或无效怎么办?你能证实这种路径存在吗? :-) –

+0

是的,看看“print working directory”结果我的路径:[student @ rhel7 Visual Studio Code] $ pwd /home/student/Documents/Visual Studio代码 [student @ rhel7 Visual Studio Code] $ ls -l矩形 -rw-rw-r--。 1名学生287 5月24日13:27 rectangle –

回答

1

是 “矩形” 提交您的C++上面提到的源代码?

如果是这样,它应该按惯例被重新命名为“rectangle.cpp”,然后编译为二进制/可运行程序 - 可以命名为“矩形”。

据我所知,您必须使用VSCODE外部的编译器,但可以设置一个编译任务自动完成的构建任务(以及一个文件监视器和一个问题匹配器,如果您感觉先进)。

+0

我将名称改为rectangle.cpp,并使用cpp编译它。然后我在VS中打开它。我尝试了>运行并>运行生成任务,但无法运行。编译命令是:“cpp rectangle.cpp -o rectangle”我需要做什么?我怀疑是我的launch.json文件配置不正确。你可以看看我的第一篇文章,并建议如何配置它,如果这是必要的? –

+0

编译命令看起来确定 - 不确定生成了多少调试信息,但是对于运行它看起来是最低要求。我相信运行命令(任务)的json文件与用于调试的json文件不同。你能显示你的“tasks.json”文件吗? –

+0

感谢(!)每个人,但我因为我在Redhat for C++(Anjuta和CodeBlocks)上找到了2个优秀的程序,所以我放弃了VS代码:) –

0

你是在同一时间安装Cygwin和minGW还是只安装Cygwin?
在以上两种情况下,请确保VSCODE调用minGW的g ++和gdb,只需添加minGW的bin路径,并从系统环境中删除Cygwin的bin路径即可。 因为由Cygwin构建的exe依靠cygwin1.dll,这不是纯粹的双赢exe,所以gdb不能用这个exe很好。

相关问题