当我调试一个C程序时,我遇到了这个错误:preLaunchTask 'C/C++:gcc.exe build active file'终止,退出代码为-1

uurv41yg  于 2023-06-28  发布在  C/C++
关注(0)|答案(2)|浏览(960)

我是一个C编程新手。我遇到了错误:(preLaunchTask 'C/C++:gcc.exe build active file'以退出代码-1终止)当我调试时,如下所示:

我的launch.json是:

"version": "0.2.0",
    "configurations": [
        {
            "name": "gcc.exe - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc.exe build active file"
        }
    ]
}

我的tasks.json是:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe build active file",
            "command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe",
            "args": [
                "-g",
                "${workspaceFolder}\\*.c",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: \"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe\""
        }
    ]
}
lztngnrs

lztngnrs1#

“程序”:“${fileDirname}${fileBasenameNoExtension}.exe”,
1.您需要在{fileDirname}中给予包含文件的目录名
1.您需要在{fileBasenameNoExtension}中给予可执行文件的名称

ubof19bj

ubof19bj2#

看起来你是从中国来的。请检查:

  1. If the folder of your program contains non-English words. (for Chinese, don't create the folder in Desktop "桌面")
    1.如果有空格或其他可能影响编译的字符。在我的例子中,我的文件夹包含一个“&”,当我查找为我生成的命令VSCode时,该命令不包含“&”之后的所有内容,并且无法找到正确的可执行文件。
    这是一个很好的做法,使您的文件夹名称干净。希望这有帮助!

相关问题