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

linux - VS Code cannot find the path of C++ binary in WSL - Stack Overflow

programmeradmin1浏览0评论

I have a C++ project in WSL, and VS Code on the windows side. Say my C++ binary is at: /home/myhome/bin/test, then in /home/myhome, I launch the VS Code: >code . In VS Code, the launch.json is like:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "WSL: Debug C++ Project",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/bin/test",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build C++ Project"
        }
    ]
}

But when debugging, VS Code complains: \\wsl.localhost\Ubuntu\home\myhome: No such file or directory

I also tried:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "WSL: Debug C++ Project",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/myhome/bin/test",
            "args": [],
            "stopAtEntry": false,
            "cwd": "/home/myhome",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build C++ Project"
        }
    ]
}

This time, the error message is "\home\myhome\bin\test" cannot be found. I notice in the error message it becomes back slash. Does anyone know what is missing here?

I have a C++ project in WSL, and VS Code on the windows side. Say my C++ binary is at: /home/myhome/bin/test, then in /home/myhome, I launch the VS Code: >code . In VS Code, the launch.json is like:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "WSL: Debug C++ Project",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/bin/test",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build C++ Project"
        }
    ]
}

But when debugging, VS Code complains: \\wsl.localhost\Ubuntu\home\myhome: No such file or directory

I also tried:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "WSL: Debug C++ Project",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/myhome/bin/test",
            "args": [],
            "stopAtEntry": false,
            "cwd": "/home/myhome",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build C++ Project"
        }
    ]
}

This time, the error message is "\home\myhome\bin\test" cannot be found. I notice in the error message it becomes back slash. Does anyone know what is missing here?

Share Improve this question asked 29 mins ago xymzhxymzh 16510 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The error occurs because VS Code is using Windows-style paths instead of Linux paths in WSL.

1.Use the Remote-WSL extension to ensure VS Code runs inside WSL.

2.Update launch.json with Linux paths and specify gdb's location:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "WSL: Debug C++",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/myhome/bin/test",
            "args": [],
            "cwd": "/home/myhome",
            "MIMode": "gdb",
            "miDebuggerPath": "/usr/bin/gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build C++ Project"
        }
    ]
}

Steps.

S-1.Open your project in WSL by running code . inside WSL.

S-2.Ensure the C++ extension is installed in the WSL side of VS Code.

S-3.Use the corrected launch.json above.

发布评论

评论列表(0)

  1. 暂无评论