I have debug versions of libstdc++ and libc, among others, and would like to link against them. They live in /usr/lib/debug as opposed to /usr/lib. Any ideas?
Use linker flags. ld/gcc -L<LIBRARY_PATH>
is important for link time only, regardless shared or static, you cannot link against library, if linker can't find it.
For shared libraries environment variable LD_LIBRARY_PATH
is important for start up time. Dynamic libraries loader ld.so and ld-linux.so will look up there when you start your application.
Assuming Linux,
-L/usr/lib/debug
to your linker command line. gcc
/ld
will look there before default system directories. Use ldd
command to verify that correct library versions were linked against (shared libraries only).LD_LIBRARY_PATH=usr/lib/debug
, and your application will pick up libraries from there even without step 1, as long as there is a version of a library, which is very likely if you are installing with distribution's package manager.It's a good idea to do both, though, as some libraries may be only in static form.
I believe the accepted answer is misleading in that the libraries in /usr/lib/debug
is not a debug compiled (-g -O0 ...) version of libraries in /lib
,/usr/lib
but simply debug symbols stripped from the corresponding library in /lib
,/usr/lib
. See the explanation the accepted answers to How to use debug version of libc and for How to link against debug versions of libc and libstdc++ in GCC? more details.
Quotes:
The libraries in
/usr/lib/debug
are not real libraries. Rather, the contain only debug info, but do not contain.text
nor.data
sections of the real libc.so.6
and
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.
Check yourself with:
objdump -h /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.19.so | grep -C1 text
11 .text 001488a3 000000000001f520 000000000001f520 000002b4 2**4
ALLOC, READONLY, CODE
The .text
segment is ALLOC
but without CONTENTS
. Compare with the corresponding library in /lib/x86_64-linux-gnu/libc-2.19.so
:
$ objdump -h /lib/x86_64-linux-gnu/libc-2.19.so | grep -C1 text
11 .text 001488a3 000000000001f520 000000000001f520 0001f520 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE