如何链接到GCC中libc和libstdc ++的调试版本? [英] How to link against debug versions of libc and libstdc++ in GCC?

查看:208
本文介绍了如何链接到GCC中libc和libstdc ++的调试版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题,但这似乎并不适用于我。

I am aware of this question, but it does not appear to work for me.

对于设置, C ++程序, hw.cpp ,由: int main(){}

For the setup, take a simple C++ program, hw.cpp, given by: int main() { }

在Linux上编译时使用 g ++ -o hw hw.cpp -O0 -g ,运行 ldd ./hw给出:

Upon compiling with g++ -o hw hw.cpp -O0 -g on Linux, running ldd ./hw gives:

    linux-gate.so.1 =>  (0x003e5000)
    libstdc++.so.6 => /usr/local/lib/libstdc++.so.6 (0x007c5000)
    libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0x006a4000)
    libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1 (0x00a40000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00a93000)
    /lib/ld-linux.so.2 (0x00a0f000)

现在我也看起来在 / usr / lib / debug / lib / tls / i686 / cmov / 中有调试库,我想象的是相应的系统库的调试版本。

Now I also appear to have debug libraries in /usr/lib/debug/lib/tls/i686/cmov/, which I imagine are the corresponding debug builds of the system libraries.

问题:如何编译我的程序,以便与标准C和/或C ++库的调试版本, libc / libm / libstdc ++ ,共享还是静态?对于共享版本,我希望 ldd ./hw 的输出指向调试目录。

Question: How do I compile my program so that it is linked against the debug builds of the standard C and/or C++ libraries, libc/libm/libstdc++, shared or static? For the shared build, I want the output of ldd ./hw to point to the debug directory.

< (背景:我的项目使用的一个共享库被Valgrind报告为泄漏(仍然可以),但是起源不在共享库本身,而是在dlopen类型的代码中(看到这里)所以我想,如果我可以通过 _Start()在CRT中调用我可能可以追查凶手。)

(Background: One of the shared libraries that's used by my project is reported as leaking ("still reachable") by Valgrind, but the origins are not in the shared library itself, but in dlopen-type code (see here). So I figured that if I can step through the _Start() invocation in the CRT I might be able to trace the culprit.)

更新/更正:我想我只是非常非常愚蠢 - 调试库可能总是一直被链接到一起。调试器在编程时没有显示任何东西,我感到困惑,这是因为我没有图书馆的源代码

Update/Correction: I think I was just very, very stupid - the debug libraries have probably always been linked as desired all along. I was confused by the debugger not showing anything while stepping, which is because I don't have the source code for the libraries.

更新II:确定,保留以前的更新。我现在有图书馆资源,但是标准库附带调试符号确实是这样,我似乎没有单独的调试构建。是否可以使用这样的构建方法?如何链接?

Update II: OK, belay the previous update. I have the library sources now, but while it is true that the standard library ships with debug symbols, I don't appear to have a separate debug build. Is such a build available, and how would I link against it?

推荐答案

在许多Linux安装中,调试库不包含真实的码;它们只包含调试信息。这两个是分开的,以便您可以选择不安装它们,如果您不需要它们,而且您的磁盘空间不足,但是调试库本身并不好。

On many Linux installations the debug libraries do not contain real code; they only contain the debug info. The two are separated so that you can choose not to install them if you don't need them and you are short of disk space, but the debug libraries are no good on their own.

GDB通常是预先配置的,以便在需要时找到调试库。

GDB is normally preconfigured to find the debug libraries when you need them.

当然,您的系统可能会有所不同。你不说什么。

Of course, your system maybe different. You don't say what it is.

这篇关于如何链接到GCC中libc和libstdc ++的调试版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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