0

I am new to C/C++. I have been reading up on debugging with gdb, and the examples I have seen are simple, and compile a main.c or main.cpp file and then run the file. My question is if it is possible to compile a library with debug symbols? In the case of a shared library, if I ran the following commands
gcc -c -g -fpic test.cpp -I include
gcc -shared -o libtest.so test.o
I would expect the output to be libtest.so, but this is a library and not an executable. How would you go about debugging the .cpp files within the library?

  • First, compile your library with `-ggdb` then link it to your program and call the library functions and start tracing. – Ghasem Ramezani Aug 16 '21 at 04:30
  • You need to use `-g` when linking as well as compiling. You should also use `g++` not `gcc` when building and linking c++ code – Alan Birtles Aug 16 '21 at 06:16

0 Answers0