Subject: [Boost-build] an implementation of msvc pdb file management for msvc.jam
From: Michael Weber (michael.weber_at_[hidden])
Date: 2009-04-17 15:57:19
Attached is a proposed implementation of PDB file management for
msvc.jam that I am using on my project. These are changes relative to
the 1.36.0 release and include notes about the implementation -- you
can search on "PDB_" to find the relevant sections.
By default, when using <debug-symbols>on/<debug-store>database (msvc
compiler option /Zi) for external debug databases, MSVC will generate
a file named vc<ver>.pdb in the build folder. These files are
inconvenient when you need to copy PDB files around for debugging, or
if you want to check a .lib / .pdb pair for a pre-built third party
library into source control, or if you simply want better accounting
of PDB files. Multiple targets can otherwise clobber each other's pdb
files in a given project.
The MSVC tools create a challenge. The compiler can generate pdb files
during compilation, and the linker can generate pdb files when linking
executables. However, the library archiver does NOT generate pdb
files. If you invoke "link.exe /lib" it actually executes lib.exe, and
lib.exe does not include a /pdb option, nor does it automatically
compile individual pdb files from the compilation state into one. If
you want a pdb file named <libname>.pdb, your only option is to use
that name during the compile phase for all contributing source.
My solution is as follows:
1. When compiling source for an executable target, the compile-c-c++
rule intializes PDB_NAME on a per-source basis. i.e., foo.cpp gets
foo.pdb, and the compile-c-c++ action uses it with the optional
PDB_CFLAG. The linker automatically collects them together into
2. When compiling source for a library target, the (newly added)
archive rule replaces the value of PDB_NAME with <libname>.pdb for
each source file. This way, the compiler will put the pdb info for all
source files into a single pdb file named after the library.
I just noticed at the last minute that PDB_LINKFLAG is not actually
hooked into msvc.jam's linker invocation, but I'm getting the desired
pdb files anyways -- I guess it is generated by default if the source
was compiled as such. This option could be used if someone wants a pdb
name different from their executable name. But as attached, PDB files
are managed better than with the default msvc.jam.
Also, when compiling source for executables, creating a unique pdb for
each source file may not be necessary. But the target binary's name is
not readily accessible from the compile rule, and pdb-per-cpp is safe
(files should not clobber each other) and easy.
Thanks for a superb build system!
Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk