Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

Are libraries already compiled?

Libraries are precompiled for several reasons. First, since libraries rarely change, they do not need to be recompiled often. It would be a waste of time to recompile the library every time you wrote a program that used them.

Does a compiler link to library code?

Technically your compiler does not figure out which libraries will be used. The linker (commonly ld ) does this. The header files only tell the compiler what interface your library functions use and leaves it up to the linker to figure out where they are.

Are shared libraries compiled?

Libraries are an indispensable tool for any programmer. They are pre-existing code that is compiled and ready for you to use.

What is static library gcc?

A static library is basically a set of object files that were copied into a single file with the suffix . a . The static file is created with the archiver ( ar ). ar rcs bin/static/libtq84.a bin/static/add.o bin/static/answer.o. Github respository gcc-create-library, path: /steps/create-static-library.


If you're running on Linux, use objdump --debugging. There should be an entry for each object file in the library. For object files without debugging symbols, you'll see something like:

objdump --debugging libvoidincr.a
In archive libvoidincr.a:

voidincr.o:     file format elf64-x86-64

If there are debugging symbols, the output will be much more verbose.


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.


What helped is:

gdb mylib.so

It prints when debug symbols are not found:

Reading symbols from mylib.so...(no debugging symbols found)...done.

Or when found:

Reading symbols from mylib.so...done.

None of earlier answers were giving meaningful results for me: libs without debug symbols were giving lots of output, etc.


nm -a <lib> will print all symbols from library, including debug ones.

So you can compare the outputs of nm <lib> and nm -a <lib> - if they differ, your lib contains some debug symbols.