You have to ensure googletest and your project are built using the same version of the C Runtime Library (CRT). Google test (currently v1.6.0) provides 2 Visual Studio solution files; gtest-1.6.0\msvc\gtest.sln
which uses the static version and gtest-1.6.0\msvc\gtest-md.sln
which uses the dynamic (dll) version. By default, projects created via Visual Studio use the dll version.
You need to decide whether you want your project to use the static or dynamic versions of the CRT.
To set your project to use the static versions, go to Project->Properties
and at the top left of the window, select Configuration: Debug
. Then in this same window select Configuration Properties
-> C/C++
-> Code Generation
. The option for Runtime Library
should be Multi-threaded Debug (/MTd)
.
You then need to ensure you're linking to the appropriate versions of gtest, so select Configuration Properties
-> Linker
-> Input
. Edit the Additional Dependencies
field by providing the full path to the Debug version of the gtest library (e.g. C:\gtest-1.6.0\msvc\gtest\Debug\gtestd.lib
).
Do the same again for Release Configuration, but setting the Runtime Library
option to Multi-threaded (/MT)
and providing the full path to the Release version of the gtest library (e.g. C:\gtest-1.6.0\msvc\gtest\Release\gtest.lib
).
If you decide you want to use the dll versions of the CRT, choose Multi-threaded Debug DLL (/MDd)
and Multi-threaded DLL (/MD)
, and link to the gtest-md libraries which will be in gtest-1.6.0\msvc\gtest-md\...
rather than gtest-1.6.0\msvc\gtest\...
.