最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Debugging a C program in VSCode with GCC and GDB fails due to space in path - Stack Overflow

programmeradmin1浏览0评论

I have a C source code file called main.c located in the directory:

C:\Users\arnau.blanco\OneDrive - Company\Desktop\code

I am trying to debug this file using VSCode on Windows. I have GCC, GDB, and Cygwin installed and configured, and I’m using the C++ (GDB/LLDB) debugger.

Steps to Reproduce:

  1. I go to "Run and Debug" and click on the "Run and Debug" button.

  2. I select the C++ (GDB/LLDB) debugger and it starts debugging, but I get the following error:

    Unable to start debugging. Program path 'C:\Users\arnau.blanco\OneDrive - Company\Desktop\code\main.exe' is missing or invalid.

    GDB failed with the message: /cygdrive/c/Users/arnau.blanco/OneDrive: Is a directory.

    This may occur if the process's executable was changed after the process was started, such as when installing an update. Try re-launching the application or restarting the machine.

    [Open 'launch.json'] [Cancel]

What I’ve Tried:

  1. Manually compiling the program:
    gcc -g "C:\Users\arnau.blanco\OneDrive - Company\Desktop\code\main.c" -o "C:\Users\arnau.blanco\OneDrive - Company\Desktop\code\main.exe"
    
    

This works fine, and the executable is created successfully.

  1. Running GDB manually in the terminal:

    gdb "C:/Users/arnau.blanco/OneDrive - Company/Desktop/code/main.exe"
    
    

This also works as expected.

My configuration

This is my tasks.json file:

{
"version": "2.0.0",
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: gcc.exe build active file",
        "command": "C:\\cygwin64\\bin\\gcc.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "compiler: C:\\cygwin64\\bin\\gcc.exe"
    }
]
}

Questions:

  1. Is this error caused by the spaces in my file path (e.g., OneDrive - Company)?
  2. If so, how can I configure VSCode to correctly handle paths with spaces?

I appreciate any guidance on this! Let me know if you need more details about my setup.

发布评论

评论列表(0)

  1. 暂无评论