How can I tell if a library was compiled with -g?

Dan Hook picture Dan Hook · Jan 4, 2010 · Viewed 57.6k times · Source

I have some compiled libraries on x86 Linux and I want to quickly determine whether they were compiled with debugging symbols.

Answer

Alex InTechno picture Alex InTechno · Oct 9, 2012

The suggested command

objdump --debugging libinspected.a
objdump --debugging libinspected.so

gives me always the same result at least on Ubuntu/Linaro 4.5.2:

libinspected.a:     file format elf64-x86-64
libinspected.so:     file format elf64-x86-64

no matter whether the archive/shared library was built with or without -g option

What really helped me to determine whether -g was used is readelf tool:

readelf --debug-dump=decodedline libinspected.so

or

readelf --debug-dump=line libinspected.so

This will print out set of lines consisting of source filename, line number and address if such debug info is included into library, otherwise it'll print nothing.

You may pass whatever value you'll find necessary for --debug-dump option instead of decodedline.