VS 代码C++:无法启动调试 - 程序路径丢失或无效
C++ for VS code: Unable to start debugging - Program path is missing or invalid
无法启动调试。程序路径"/home/student/Documents/Visual Studio Code/rectangle"缺失或无效。
我的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;
}
"矩形"文件是上面提到的C++源代码吗?
如果是这样,按照惯例,它应该重命名为"矩形.cpp",然后编译成二进制/可运行程序 - 可以命名为"矩形"。
据我所知,您必须使用 VSCODE 外部的编译器,但可以设置一个构建任务(如果您感觉高级,还可以设置文件观察器和问题匹配器)来自动执行编译过程。
您是同时安装 Cygwin
和 minGW 还是只是安装 Cygwin?
在以上两种情况下,请确保VSCODE调用minGW的g++和gdb,您只需添加minGW的bin路径并从系统环境中删除Cygwin的bin路径即可。因为 Cygwin 构建的 exe 依赖于 cygwin1.dll这不是纯 win exe,所以 gdb 不能很好地处理这个 exe。
相关文章:
- 如何在 c++ 中正确指定 #include 路径以使程序可移植
- 如何在没有"路径"模块的情况下加载 cheerp-wasm 程序?
- 如何使特定程序仅从安装的路径运行以避免DLL劫持
- 如何从 CLion 的运行窗口中删除程序项目路径
- 更改应用程序数据的路径
- CMake导出的库-在客户端应用程序中找不到include/Lib路径
- 在 Linux 上,在 C++ 程序中,如何找到已加载共享库的路径?
- 按名称问题获取卸载应用程序路径
- 提供依赖于输入的程序的文件路径
- 程序文件中的安装路径:一些问题
- 崇高文本 3 - 在终端中编译并运行 C++ 程序(路径包含空格)
- 通过程序代码行设置C++包含路径
- QT MAC应用程序存储数据路径
- Visual Studio:C++\CLI 包装程序集路径依赖性问题
- 在 CreateProcess 的路径中使用 SHGetKnownFolderPath 来运行程序
- 如何将应用程序URI转换为普通文件路径
- 如何使用QT程序中的默认应用程序打开使用相对路径的PDF
- 运行 c++ 程序时搜索的路径错误
- 如何使用QT检查程序是否存在于路径中
- C++ 程序 [窗口] 的资产文件夹路径