使用标准 C++ 库调试符号?Ubuntu/Linux/libstdc++6-8-dbg? [英] Using standard C++ library debug symbols? Ubuntu / Linux / libstdc++6-8-dbg?

查看:77
本文介绍了使用标准 C++ 库调试符号?Ubuntu/Linux/libstdc++6-8-dbg?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Ubuntu Linux(撰写本文时的最新版本)上有一个名为 libstdc++6-8-dbg 的包.

There is a package called libstdc++6-8-dbg on Ubuntu Linux (latest version at time of writing).

它被描述为:

GNU 标准 C++ 库 v3(调试文件)这个包包含 libstdc++ 的共享库调试符号.

GNU Standard C++ Library v3 (debugging files) This package contains the shared library of libstdc++ compiled with debugging symbols.

其中包含以下文件:

/usr/lib/x86_64-linux-gnu/debug/libstdc++.a
/usr/lib/x86_64-linux-gnu/debug/libstdc++.so.6.0.25
/usr/lib/x86_64-linux-gnu/debug/libstdc++fs.a

通常用 gcc 编译一个(单个翻译单元)C++ 程序,你可以这样写:

Normally to compile a (single translation unit) C++ program with gcc you can write:

$ g++ myprogram.cc

要添加生成用户代码的调试符号,您可以通过 -g:

To add generation of debug symbols of user code you pass -g:

$ g++ -g myprogram.cc

但这不包括标准库的调试版本.

But this doesn't include the debug versions of the standard library.

您需要向 g++ 传递哪些额外选项来告诉它使用 libstdc++6-8-dbg 提供的标准库的调试版本?

What extra options do you need to pass to g++ to tell it to use the debug versions of the standard library provided by libstdc++6-8-dbg?

推荐答案

一旦您安装了软件包,GDB 就会自动读入调试符号.您不需要以任何不同的方式编译您的程序.

GDB automatically reads in the debug symbols once you've installed the package. You don't need to compile your program any differently.

如果您希望程序加载调试版本,最好的办法是调整库搜索路径.您可以通过临时设置 LD_LIBRARY_PATH 来实现:

If you want your program to load the debug version your best bet is to adjust the library search path. You could do that by setting LD_LIBRARY_PATH temporarily:

$ LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/debug/
$ ldd test
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/debug/libstdc++.so.6 (0x00007efcef670000)
        ...

或永久:

$ export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/debug/
$ ldd test
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/debug/libstdc++.so.6 (0x00007efcef670000)
        ...

或者您可以将其作为系统范围的更改.您可以在 Ubuntu 中通过将配置条目添加到 /etc/ld.so.conf.d/ 并运行 ldconfig 来更新缓存来完成此操作.

Or you could make it a system-wide change. You can do that in Ubuntu by adding a config entry to /etc/ld.so.conf.d/ and running ldconfig to update the cache.

$ sudoedit /etc/ld.so.conf.d/debug.conf
$ cat /etc/ld.so.conf.d/debug.conf
/usr/lib/x86_64-linux-gnu/debug
$ sudo ldconfig
$ ldd test
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/debug/libstdc++.so.6 (0x00007f3aced53000)
        ...

按字母顺序搜索配置文件,因此只需确保您编写的文件(上面的debug.conf)早于默认文件(x86_64-linux-gnu.conf> 在我的系统上).

The config files are searched alphabetically so just make sure the one you write (debug.conf above) comes earlier than the default one (x86_64-linux-gnu.conf on my system).

这篇关于使用标准 C++ 库调试符号?Ubuntu/Linux/libstdc++6-8-dbg?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆