PDB files with CMake install

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 PDB files. 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 PDB files to find the source files.

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

subst N: C:\MySources
N:
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.


This answer is largely based on information from this question and the links therein.


I just answered my own similar question, How to get CMake to install PDB files for targets.

Use this install rule to copy the target's PDB file, if it exists, to the target's install location bin directory.

install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION bin OPTIONAL)