squashed.bugaboo squashed.bugaboo - 1 year ago 246
C++ Question

PDB files with cmake install

I am using a CMAKE command to install PDB files to enable debugging in a developer distribution of my C++ application. The command is as below:


Also, I've managed to install the relevant source used to build that developer distribution, in a 'src' folder at the same level, so that my top level distribution folder looks as:


My question is how can I let the PDB files 'know' where the source is (I am assuming this is required)? Is there a CMAKE command that can achieve this? Appreciate a small example if you have it. Thanks for your time and interest.

Answer Source

Turning my comments into an answer; based largely on information from this question and the links in there.

PDB files store absolute path names to the source files. When not using a symbol server, the only way to ensure some degree of source code relocatability is to use the subst command.

The idea is to use subst to create a drive-letter name (e.g. N:\) for the root of the source tree. Then do your builds from this drive, so that absolute paths starting with N:\ get embedded into the PDBs. When you later need to debug the executable on a different machine, use subst on that machine to get the same absolute paths to the sources. This will enable the PDBs to find the source files.

For example, if you have a file C:\MySources\main.cpp, do the following:

subst N: C:\MySources
run your build

Later, let's say you need to debug on a machine where the same file is stored in D:\Devel\Other\main.cpp. Simply do subst N: D:\Devel\Other and then work from the N: drive there as well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download