首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法运行或调试C代码:启动:程序‘输入程序名,例如./a.out’不存在

无法运行或调试C代码:启动:程序‘输入程序名,例如./a.out’不存在
EN

Stack Overflow用户
提问于 2021-10-08 18:52:35
回答 1查看 410关注 0票数 0

我试图在Linux中使用VSCode运行和调试器,但是当我运行或调试它时会出现以下错误:

启动:程序“输入程序名称,例如/home/user/Documents/Drexel/a.out”不存在,取消或打开“launch.json”

但是a.out存在:

VSCoe终端:

代码语言:javascript
复制
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”属性不正确,我不知道如何在目录中查找和更改它们,不是Drexel,我也不知道如何在IntelliSense中查找和更改它们。

Intellisense错误地构建了这些.json

  • launch.json”不正确(见下面的代码):“程序”:“输入程序名称,例如${workspaceFolder}/a.out",
  • tasks.json不正确(参见代码/a.out)

launch.json

代码语言:javascript
复制
{
    // 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
                }
            ]
        }
    ]
}

tasks.json

代码语言:javascript
复制
{
    // 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

代码语言:javascript
复制
{
    "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
}
EN

回答 1

Stack Overflow用户

发布于 2021-10-08 21:34:58

更改:

代码语言:javascript
复制
"program": "enter program name, for example ${workspaceFolder}/a.out",

代码语言:javascript
复制
"program": "${workspaceFolder}/a.out",
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69500533

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档