Static library debug symbols
If you use /ZI
or /Zi
(C/C++
-> General
-> Debug Information Format
), then the vc$(PlatformToolsetVersion).pdb
is created, which contains the debug info for all of the .obj
files created. If alternately you use /Z7
, the debug info will be embedded into the .obj
file, and then embedded into the .lib
. This is probably the easiest way to distribute the debug info for a static library.
I wouldn't advise distributing a static library, however, since it's generally tied to a specific version of the compiler.
How to separate debug symbols from a C static library and later load it in GDB
Don't do this:
objcopy --only-keep-debug lib_mylib.o lib_mylib.o.debug
(It only works for shared libraries.)
Do this instead:
cp lib_mylib.o lib_mylib.o.debug
Even easier may be to keep lib_mylib.o
untouched, and strip debug symbols from the executable at link time:
gcc -g driver.c -o driver -L. -l_mylib -Wl,-s
And easier still: link the binary with debug info and keep it for debugging, but use stripped executable where you need it to be stripped:
gcc -g driver.c -o driver-dbg -L. -l_mylib &&
strip -g -o driver driver-dbg
With above, you wouldn't need to add-symbol-file
, just point GDB to driver-dbg
and it will do everything automatically.
Strip/Remove debug symbols and archive names from a static library
This script implements Sigismondo's suggestion (unpacks the archive, strips each object file individually, renames them 1000.o
, 1001.o
, etc., and repacks). The parameters for ar crus
may vary depending on your version of ar
.
#!/bin/bash
# usage: repack.sh file.a
if [ -z "$1" ]; then
echo "usage: repack file.a"
exit 1
fi
if [ -d tmprepack ]; then
/bin/rm -rf tmprepack
fi
mkdir tmprepack
cp $1 tmprepack
pushd tmprepack
basename=${1##*/}
ar xv $basename
/bin/rm -f $basename
i=1000
for p in *.o ; do
strip -d $p
mv $p ${i}.o
((i++))
done
ar crus $basename *.o
mv $basename ..
popd
/bin/rm -rf tmprepack
exit 0
Related Topics
C++ Concept That Requires a Member Function with an Outputiterator as Parameter
Why Statements Cannot Appear at Namespace Scope
How to Support Both Ipv4 and Ipv6 Connections
Why Is Auto_Ptr Being Deprecated
Copying Std::Vector: Prefer Assignment or Std::Copy
Difference Between C++11 Std::Bind and Boost::Bind
How to Use the Priority Queue Stl for Objects
How to Get the Maximum or Minimum Value in a Vector
Where Would You Use a Friend Function VS. a Static Member Function
Should I Use Wchar_T When Using Utf-8
Does This Type of Memory Get Allocated on the Heap or the Stack
Default Parameters with C++ Constructors
Complete Example Using Boost::Signals for C++ Eventing
How Can Std::Unique_Ptr Have No Size Overhead
Why Does Nvcc Fails to Compile a Cuda File with Boost::Spirit