Enabling debug symbols in shared library using GCC

24,541

You need to use -g for all the steps (compiling your source files and linking).

Share:
24,541
Alphaneo
Author by

Alphaneo

An electrical engineer, who is a programmer by profession

Updated on March 11, 2020

Comments

  • Alphaneo
    Alphaneo about 4 years

    I am creating a shared library using gcc and suspect that there may be some memory leaks from the shared library. To debug, I need to enable debug symbols when creating the shared library.

    To build, I am using gcc -g ... (-g is for enabling debug information)

    But the library (*.so file) size is not changing for both -g, and without -g. Besides, I am not getting any useful information from tools like VALGRIND.

    Can anyone point me the mistake?

    • Tim Post
      Tim Post almost 15 years
      Can you post the relevant parts of your makefile, or the other CFLAGS being used?
    • Alphaneo
      Alphaneo almost 15 years
      I added -g to CFLAGS and it worked, thanks !!!
  • Manuel
    Manuel over 9 years
    Also make sure you don't specify -s when linking, because this strips debug info.
  • aleixrocks
    aleixrocks over 6 years
    The -g flag is not really needed for the gnu linker as the ld man page says: "-g Ignored. Provided for compatibility with other tools.". It is only required for the compilation stage.