首页 > 解决方案 > 无法运行或调试 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 似乎工作这不是它可能的问题:

Intellisense 错误地构建了这些 .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
}

标签: visual-studio-codegdb

解决方案


改变:

"program": "enter program name, for example ${workspaceFolder}/a.out",

"program": "${workspaceFolder}/a.out",

推荐阅读