I'm having trouble setting up a googletest unit test project with Visual Studio 2019 for an existing project.
I started by choosing New > Project
from VS and choosing googletest. The project stub that was created by VS compiles and runs fine.
I added the project I'm trying to test to the unit test's References. The project is in the same solution.
When I tried testing one of my classes, the test compiled fine. The linker couldn't find my class, though. So I added the .obj
file from the other project to the unit test project's linker dependencies (Properties > Linker > Additional dependencies
). Now I get another linker error:
gtestd.lib(gtest-all.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary':
value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug'
I can't change the settings of the project I'm trying to test because of various reasons (incompatibilities with other libraries). So I changed the settings of the unit tests project (Properties > C/C++ > Code Generation > Runtime Library
). However, I still get the same linker error, probably because gtestd.lib
itself is fixed to MDd_DynamicDebug
. How can I change that?
I searched the web, and all I found is some information on how you would do this with CMake
, but not with Visual Studio
.