admin管理员组

文章数量:1298409

I am trying to set up debugging for C code with gdb in VS CODE in WSL Ubuntu 22.04 on Windows 10.

I followed the steps on the Get Started page.

However, I'm unable to Debug or even Run within VS Code. The files run and debug with gdb in the WSL terminal fine.

When I try to Run or Debug, I get a pop up windows saying:

"The preLaunchTask 'C/C++: gcc.exe build active file' terminated with exit code -1.

In the VS Code Terminal, I see the following message:

/bin/sh: 1: C:MinGWbingcc.exe: not found

My config files are shown below.

c_cpp_properties.json

{
"configurations": [
  {
    "name": "Linux",
    "includePath": ["${workspaceFolder}/**"],
    "defines": [],
    "compilerPath": "/usr/bin/gcc",
    "cStandard": "c11",
    "cppStandard": "c++17",
    "intelliSenseMode": "clang-x64"
  }
],
"version": 4
}

launch.json

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: /?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/my_out_file",
        "args": ["arg1", "arg2", "arg3"],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "/usr/bin/gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "preLaunchTask": "C/C++: gcc.exe build active file"
    }

]
}

tasks.json

{
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: cl.exe build active file",
        "command": "cl.exe",
        "args": [
            "/Zi",
            "/EHsc",
            "/nologo",
            "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
            "${file}"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$msCompile"
        ],
        "group": "build",
        "detail": "Task generated by Debugger."
    },
    {
        "type": "cppbuild",
        "label": "C/C++: gcc.exe build active file",
        "command": "C:\\MinGW\\bin\\gcc.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "Task generated by Debugger."
    }
],
"version": "2.0.0"
}

settings.json

{
"C_Cpp.defaultpilerPath": "C:\\MinGW\\bin\\gcc.exe"
}

My PATH variable contains /mnt/c/Users/me/AppData/Local/Programs/Microsoft VS Code/bin:

What am I missing here? Any help is appreciated.

本文标签: Cannot Run or Debug C code in VS Code in WSL on Windows 10Stack Overflow