【问题标题】:How do I get VS Code on WSL to debug my C++ code?如何在 WSL 上获取 VS Code 来调试我的 C++ 代码?
【发布时间】:2020-10-01 15:05:07
【问题描述】:

我已经在我的 Windows 10 系统上安装了 Ubuntu 20.04。在我第一次在 Ubuntu 中运行 VS Code 之前,VS Code 在 Windows 中运行良好。现在,我可以在那里构建我的 C++ 应用程序,但无法调试它。我收到一个警告框,提示“在 PATH 上找不到运行时 'node'。是否安装了 'node'?”

每当我启动 VS Code 时,一个名为“node”的后台进程也会启动,所以我假设 VS Code 会启动它。我的 Ubuntu 安装在 ~/.vscode-server 的各个子目录中有大约八个版本的 node.js。

这是我的 launch.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": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/gametest",
            "skipFiles": [
                "<node_internals>/**"
            ]
        },
    ]
}

我尝试安装最新的 nodejs。我不再收到带有未找到消息的警告框,但 VS Code 中的调试控制台现在显示:

/usr/bin/node /home/jon/projects/KSolve/gametest
Debugger listening on ws://127..... (can't copy from debug console window)
For help, ...
/home/jon/projects/KSolve/gametest:1
 ELF(three squares)
^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    ...
...
Process exited with code 1

【问题讨论】:

  • 如果您能提供有关您的 C++ 项目的更多详细信息,将更容易回答您的问题。你在使用 CMake 等吗?

标签: c++ visual-studio-code windows-subsystem-for-linux


【解决方案1】:

前段时间对我来说,在 WSL Ubuntu 下的 VS Code 上运行调试器也很棘手。经过多次尝试,我得到了下一个.vscode/launch.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": "test tree",
            "type": "cppdbg",
            "request": "launch",
            "program": "enter program name, for example ${workspaceFolder}/tests/ttree",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/tests",
            "environment": [],
            "externalConsole": false,
            "targetArchitecture": "x86_64",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

【讨论】:

    猜你喜欢
    • 2020-03-18
    • 1970-01-01
    • 2019-09-24
    • 1970-01-01
    • 2022-11-05
    • 2019-01-01
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    相关资源
    最近更新 更多