visual-studio-code - 无法运行或调试 C 代码:启动:程序“输入程序名称,例如 ./a.out”不存在
问题描述
我正在尝试在 Linux Ubuntu 中使用 VSCode 运行和调试器,但是当我运行或调试时,它会出现此错误:
启动:程序“输入程序名称,例如/home/user/Documents/Drexel/a.out”不存在取消或打开“launch.json”
但是 a.out 存在:
VSCoe 终端:
user:~/Documents/Drexel$ g++ helloworld.c
user:~/Documents/Drexel$ ./a.out
Hello C++ World from VS Code and the C++ extension!
user:~/Documents/Drexel$ gcc ccadd.c
user:~/Documents/Drexel$ ./a.out
Usage: ccadd maker model year cpu id desc
所以 a.out 似乎工作这不是它可能的问题:
- “program”和“cwd”属性不正确,我不知道如何在 IntelliSense 中查找和更改它们
- 工作目录不是 Drexel,我不知道如何在 IntelliSense 中查找和更改它
Intellisense 错误地构建了这些 .json
- launch.json 不正确(参见下面的代码):“program”:“输入程序名称,例如 ${workspaceFolder}/a.out”,
- tasks.json 不正确(参见下面的代码)
- c_cpp_properties.json 不正确(参见下面的代码)
启动.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
//"cwd": "/usr/bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
任务.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "msbuild",
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true",
"/t:build",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
},
{
"name": "gcc",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
解决方案
改变:
"program": "enter program name, for example ${workspaceFolder}/a.out",
至
"program": "${workspaceFolder}/a.out",
推荐阅读
- python - 循环遍历函数内的熊猫列
- constraints - 如何将某些参数的乘法约束为lmfit中的常数值?
- vba - 保存特定附件
- r - 在格式化表中向 color_bar 添加填充距离
- c++ - 在 C++ 中更快的构建时间
- android - AOSP 是否支持注音(Bopomofo)语言的虚拟键盘?
- python-3.x - 如何让两个客户端 Telethon 同时运行
- go - 在 ORM golang 中实现过滤器
- playwright - 使用 playwright.config.js 时出现“ReferenceError: playwright is not defined”
- java - Quarkus Native 的 Apache XML 安全性