调试基于 Linux 的 C++ 代码 Visual Studio 代码时出现问题

Issue while debugging Linux based C++ code visual studio code

本文关键字:代码 Studio 问题 Visual 调试 Linux C++      更新时间:2023-10-16

我正在尝试在Linux - Ubuntu的Visual Studio代码中调试我的代码。我已经根据规范配置了调试配置。但是在尝试调试时,我收到以下错误。

=thread-group-added,id="i1" GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1 版权所有 (C) 2016 自由软件基金会公司许可证 GPLv3+: GNU GPL 版本 3 或更高版本 http://gnu.org/licenses/gpl.html 这是自由软件:您可以自由更改和重新分发它。 在法律允许的范围内,没有保证。 键入"显示" 复制"和"显示保修"以了解详细信息。此 GDB 配置为 "x86_64-linux-gnu"。键入"显示配置"进行配置 详。有关错误报告说明,请参阅: http://www.gnu.org/software/gdb/bugs/。查找 GDB 手册和其他 在线文档资源: http://www.gnu.org/software/gdb/documentation/。如需帮助,请键入 "救命"。键入"apropos word"以搜索与"word"相关的命令。 =cmd-param-changed,param="pagination",value="off" 由于共享库事件而停止(未添加或删除库) 已加载 '/lib64/ld-linux-x86-64.so.2'.已加载符号。[劣质 1(过程 18634)退出,代码为0177] 程序 '/home/source/src/.libs/main' 已退出,代码为 177 (0x000000b1)。

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": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x64",
"program": "${workspaceFolder}/src/.libs/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
},
]
}

因为并非所有库(.a,.so)都链接到您的项目。我有同样的问题。GDB 在遇到对未链接库的库调用时输出此错误。

您在没有调试信息的情况下编译了程序。使用编译器和链接器选项-g编译它。