Locating pdb file of CMake RelWithDebInfo configuration

I'm trying to compile gtest with the help of CMake and VS2015. I have found that no pdb file is generated in the output folder. Let's try to solve this issue.

Environment

We're using CMake, Visual Studio to compile google test with the versions listed below:

Util Version Downloading URL
CMake 3.12.0 https://cmake.org/files/v3.12/cmake-3.12.0-win64-x64.msi
VS 2015 14.0 https://go.microsoft.com/fwlink/?LinkId=532606&clcid=0x409
google test 1.8.0 https://github.com/google/googletest/archive/release-1.8.0.zip

We tried CMake 3.11.4 as well and then inferred that this might be a bug in cmake, so we upgraded it, but it didn't work either.

Steps to reproduce

  1. Unzip google test archive.
  2. Launch VS2015 x64 Native Tools Command Prompt and switch to the unzipped

google test folder, run the following command to generate sln file:

mkdir build
cd build
cmake .. -G"Visual Studio 14 2015"
  1. Open build\googletest-distribution.sln
  2. Compile ALL_BUILD with Debug config, we could find the lib and pdb files generated in build\googlemock\gtest\Debug
  3. Compile ALL_BUILD with RelWithDebInfo again, we could find the lib file in build\googlemock\gtest\RelWithDebInfo , but no pdb file
  4. Create a test project with the dependency of gtest.lib
  5. Compiler warns us the following message when compiling with the RelWithDebInfo

lib:

gtest.lib(gtest-all.obj) : warning LNK4099: PDB'gtest.pdb' was not found with 'gtest.lib(gtest-all.obj)' or at 'D:\src\ut\x64\Release\gtest.pdb'; linking object as if no debug info
  1. But no warning is displayed when we compile with the Debug lib, which

means that the pdb file is also generated for RelWithDebInfo configuration, but not copied to the output folder

Solution

At this point, we might get this idea directly: search pdb files in build folder and we could find the pdb file is located in the following folder:

build\googlemock\gtest\gtest.dir\RelWithDebInfo

This location could also be found in gtest project property, the pdb file will be copied to the same folder with the lib file if we change the $(IntDir) to $(OutDir):

https://i.loli.net/2018/08/02/5b62bd78160b6.png

So far, it is clear that the project generated by CMake does not copy pdb files to the output folder. We found that CMake had the same issue before when we search this problem online, but this issue is not solved in the latest version currently.

Conclusion

The pdb files are not copied to the output folder automatically using the solution generated by CMake with the RelWithDebInfo configuration. We should locate the files or modify the generated project property manually.