7

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?

Community
  • 1
  • 1
Yury Pogrebnyak
  • 4,093
  • 9
  • 45
  • 78
  • 2
    Did you read in the answers you linked to how everything must be built using the same runtime library configuration? The error you're getting sounds like some parts are built using the non-debug runtime and others built using the debug runtime. – Michael Burr Mar 29 '12 at 15:40

1 Answers1

7

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\....

Fraser
  • 74,704
  • 20
  • 238
  • 215