We are currently using a single command line tool to build our product on both Windows and Linux.
Si far its works nicely, allowing us to build out of source and wit
Unless you want to redistribute the static libraries with debug info, you don't actually need to merge any PDB files (or use /Z7
to embed the debug info).
As @zhaorufei mentioned, when using /Zi
, each object file contains a reference to its PDB file, which the linker then uses.
Simply use /Fd to give each object a unique PDB file:
> cl -c foo.cpp -Fo:target/foo.obj -Fd:target/foo.pdb -Zi
> cl -c bar.cpp -Fo:target/bar.obj -Fd:target/bar.pdb -Zi
> strings target/foo.obj | grep pdb
D:\Dev\sample\target\foo.pdb
> strings target/bar.obj | grep pdb
D:\Dev\sample\target\bar.pdb
This also has the benefit that it works around the issues of concurrent access to shared PDB files mentioned here, so you can parallelize the compile step like you wanted.
Then link/archive the object files as usual. VC++ already embeds various kinds of information in the object files to pass them to the linker, such as the runtime link setting and dependency libraries - the PDB file path is no different. Creating a static library from the objects does not remove the references:
> lib -out:target/all.lib target/foo.obj target/bar.obj
> strings target/all.lib | grep pdb
D:\Dev\sample\target\bar.pdb
D:\Dev\sample\target\foo.pdb
When linking this library to an executable or DLL, the linker still pulls in the debug info from the referenced PDBs and adds it to the final PDB file.
The only caveat I can see is that the path is always absolute, so this may not work if you move the files around locally or to another machine before linking.