尝试使用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.
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": "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"
}
]
}
tasks.json
{
"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"
}
答案 0 :(得分:1)
看来您做错了。您实际上是在尝试编译JSON
文件,而不是正在处理的cpp文件。您应该先切换到cpp代码的标签,然后切换到run task
或run build task
。
答案 1 :(得分:1)
达西回答,它正在尝试编译错误的文件。
在task.json文件中,您可以在args数组中看到以下行:“ $ {file}”,它的作用是填充您要编译的文件的完整路径。
此行的值针对文档(针对您的vscode)而更改。因此,可以放心地假设您正在尝试运行任务,同时将task.json文件放在焦点上,只需将其更改为要编译的.cpp文件,按F5或单击调试选项卡中的播放按钮即可,工作正常。
答案 2 :(得分:0)
发现我的问题:
"preLaunchTask": "g++ build active file",
"program":"${workspaceRoot}/TcpSocketClassTester/TcpSocketClassTester",