Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

c++ - How to link against debug versions of libc and libstdc++ in GCC?

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

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

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)

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.

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.

(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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...