Static library debug symbols
Expanding upon previous answers, for those who need the full how-to (VS 2013 minimum).
Note that this should address comments ^^above regarding VS2013 issues.
Method 1: The Program Database (.pdb) Way (/Zi or /ZI)
Static Lib Project: Generate a pdb with same name as your static lib:
- Open
Solution Explorer
from theView
menu. - Right click your static lib project, select
Properties
- Edit
Configuration Properties
->C/C++
->General
->Debug Information
to/Zi
or/ZI
- Note that
/ZI
allows "Edit and Continue" editing during debugging
- Note that
- Edit
Configuration Properties
->C/C++
->Output Files
->Program Database File Name
to$(OutDir)$(TargetName).pdb
- Now compile it, and note where YourLib.lib and YourLib.pdb are.
- Open
Application Project: Link your executable with the static lib, and new PDB file:
- Again, navigate to project properties, but this time, for your Application project
- Again, edit
Debug Information
property as needed. - Edit
Configuration Properties
->Linker
->General
->Additional Library Directories
, adding your own "libs" directory, or whatever directory you plan to keep/copy your YourLib.lib and YourLib.pdb files. - Edit
Configuration Properties
->Linker
->Input
->Additional Dependencies
, addingYourLib.lib
(no path in front) - Now copy both YourLib.lib and YourLib.pdb to the directory you specified above.
Method 2: The Embedded Symbols (no .pdb) Way (/Z7)
Static Lib Project: Generate a static lib with embedded debug symbols
- As in Method 1, navigate to project properties
- As in Method 1, modify your
Debug Information
, but this time to/Z7
- As in Method 1, compile and note where YourLib.lib is generated.
Application Project: Link you executable with the static lib
- As in Method 1, navigate to project properties
- As in Method 1, modify your
Debug Information
property as needed - As in Method 1, edit
Additional Library Directories
- As in Method 1, edit
Additional Dependencies
- Now copy YourLib.lib to the directory specified in
Additional Library Directories
Discussion:
- Advantages of Z7? It's simpler, and the "Single-file" way of doing it. All the debug info is in the lib file.
- Disadvantages of Z7? File size on-disk, link times, incompatible with "Minimal rebuild" (/Gm) feature, does not allow "Edit and Continue", older format (e.g. older paradigm)
- Why don't I specify
Debug Information
Setting for Application Project? This post is concerned with how to get debug working in static lib code. The same "Method 1 vs Method 2" choice applies for the Application project as well.
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.