I have installed google test as it’is described here. But when I try to use tests for my current project, I get 2 LNK4098 warnings:
defaultlib ‘MSVCRTD’ conflicts with use of other libs; use /NODEFAULTLIB:library
and the same for ‘LIBCMTD’, and a bunch of LNK2005 errors. But when I actually ignore these two default libraries, it doesn’t help: I get even more errors. What’s the problem?
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.slnwhich uses the static version andgtest-1.6.0\msvc\gtest-md.slnwhich 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->Propertiesand at the top left of the window, select Configuration:Debug. Then in this same window selectConfiguration Properties->C/C++->Code Generation. The option forRuntime Libraryshould beMulti-threaded Debug (/MTd).You then need to ensure you’re linking to the appropriate versions of gtest, so select
Configuration Properties->Linker->Input. Edit theAdditional Dependenciesfield 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 Libraryoption toMulti-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)andMulti-threaded DLL (/MD), and link to the gtest-md libraries which will be ingtest-1.6.0\msvc\gtest-md\...rather thangtest-1.6.0\msvc\gtest\....