使用调试器的 Vscode 错误

jdl*_*jdl 3 visual-studio-code

尝试使用 VSCODE 调试 c++ 时,出现以下错误:

> Executing task: /usr/bin/g++ -g /home/sa/Genesis/Dev/TcpSocketClassTester/.vscode/launch.json -o /home/sa/Genesis/Dev/TcpSocketClassTester/.vscode/launch <

/usr/bin/ld:/home/sa/Genesis/Dev/TcpSocketClassTester/.vscode/launch.json: file format not recognized; treating as linker script
/usr/bin/ld:/home/sa/Genesis/Dev/TcpSocketClassTester/.vscode/launch.json:1: syntax error
collect2: error: ld returned 1 exit status
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.
Run Code Online (Sandbox Code Playgroud)

启动文件

{
    // 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": "g++ build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

任务文件

{
    "tasks": [
        {
            "type": "shell",
            "label": "g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            }
        },
        {
            "type": "shell",
            "label": "g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ],
    "version": "2.0.0"
}
Run Code Online (Sandbox Code Playgroud)

小智 10

看来你搞错了。您实际上是在尝试编译JSON您正在处理的 cpp 文件以外的文件。您应该首先切换到 cpp 代码的选项卡,然后切换到run taskrun build task