Vscode 运行 调试器错误“启动程序 *file/path* 不存在
Vscode Run with debugger error "Launch program *file/path* does not exist
我想弄清楚我的编译器或 launch.json 文件有什么问题。每当我尝试 运行 vs 代码中的一个简单程序时,我都会收到错误消息。错误说,“启动程序 file_path 不存在。我尝试下载不同的编译器并向我的系统环境变量添加不同的路径。我在这一点上失去了信心。
我想我知道你的问题是哪一个,让我给你举个简单的例子:
我有一个名为 Test 的文件夹,只有 Test.cpp 个文件:
那么Test.cpp只有这个简单的代码:
#include <iostream>
using namespace std;
int main(){
cout<<"Hello World!"<<endl;
return 0;
}
编译代码并执行我是using this documentation
,检查你的 launch.json 文件我看到你使用的是相同的,但你的问题具体在你的 launch.json在名为程序的变量中:
VS Code 正在尝试仅使用工作区文件夹执行您的程序,这会导致错误,您应该在变量上使用此值 运行 并调试程序而不会出现问题:
"program": "${fileDirname}\${fileBasenameNoExtension}.exe"
${fileDirname} - the current opened file's dirname
${fileBasenameNoExtension} - the current opened file's basename with
no file extension
这样 VS Code 可以 运行 并调试编译代码后生成的可执行文件,在我的示例中,我打开了名为 test.cpp[=39= 的文件] 执行 运行 因为可执行文件是从那个文件生成的。这是末尾文件夹的顺序:
我建议您阅读这篇文章 variables for the JSON files on VS Code and this one。
我想弄清楚我的编译器或 launch.json 文件有什么问题。每当我尝试 运行 vs 代码中的一个简单程序时,我都会收到错误消息。错误说,“启动程序 file_path 不存在。我尝试下载不同的编译器并向我的系统环境变量添加不同的路径。我在这一点上失去了信心。
我想我知道你的问题是哪一个,让我给你举个简单的例子:
我有一个名为 Test 的文件夹,只有 Test.cpp 个文件:
那么Test.cpp只有这个简单的代码:
#include <iostream>
using namespace std;
int main(){
cout<<"Hello World!"<<endl;
return 0;
}
编译代码并执行我是using this documentation
,检查你的 launch.json 文件我看到你使用的是相同的,但你的问题具体在你的 launch.json在名为程序的变量中:
VS Code 正在尝试仅使用工作区文件夹执行您的程序,这会导致错误,您应该在变量上使用此值 运行 并调试程序而不会出现问题:
"program": "${fileDirname}\${fileBasenameNoExtension}.exe"
${fileDirname} - the current opened file's dirname
${fileBasenameNoExtension} - the current opened file's basename with no file extension
这样 VS Code 可以 运行 并调试编译代码后生成的可执行文件,在我的示例中,我打开了名为 test.cpp[=39= 的文件] 执行 运行 因为可执行文件是从那个文件生成的。这是末尾文件夹的顺序:
我建议您阅读这篇文章 variables for the JSON files on VS Code and this one。