2

I added gmock to my VS2019 C++ project via Nuget. Now I am receiving the below error when I try to compile. GoogleTest is the name of my test class. I am new to C++.

Suppression State Error LNK2038 mismatch detected for '_MSC_VER': value '1800' doesn't match value '1900' in GoogleTest.obj Test

What exactly does the error mean? Thank you.

Quarra
  • 2,527
  • 1
  • 19
  • 27
  • ***What exactly does the error mean?*** This means your binaries are for the wrong version of Visual Studio. – drescherjm Apr 30 '20 at 00:21
  • @drescherjm Thank you. Does this mean that the version of gmock I pulled from nuget does not work with VS2019? How should I go about fixing this? Thank you – user3667098 Apr 30 '20 at 16:38
  • I believe that is what it means. I believe you have Visual Studio 2013 binaries which are incompatible with any compiler different than VS2013 [https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B](https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B) – drescherjm Apr 30 '20 at 16:46
  • Visual Studio 2015 to 2019 are binary compatible with each other but no other versions of Visual Studio are compatible. Here is info on this compatibility: [https://learn.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017?view=vs-2019](https://learn.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017?view=vs-2019) – drescherjm Apr 30 '20 at 16:51
  • I added the tag for nuget. Hopefully that would attract people who use `nuget`. I don't. – drescherjm Apr 30 '20 at 17:01
  • That makes sense. Is there a workaround for this issue such as building from the command line instead of through Visual Studio? – user3667098 Apr 30 '20 at 17:04
  • Building outside the IDE will not fix the issue with the wrong download. – drescherjm Apr 30 '20 at 17:06
  • I think this may help: [https://www.nuget.org/packages/gmock/](https://www.nuget.org/packages/gmock/) – drescherjm Apr 30 '20 at 17:08
  • The recommended way is to use CMake and it works – Asesh Apr 30 '20 at 17:10
  • @user3667098, how did you install this nuget package? When l created a c++ project in VS2019 and then install gMock 1.10.0 by Right-click on your project-->`Manage Nuget Pakckage`--> then search `gMock ` and then install it without any errors. Right-click on your project-->`Properties`-->`Configuration Properies`-->`General`-->make sure `Toolset Plarform` is `VS2019`. After that, close VS Instance, delete any `Debug` or `Release` folder under the physical path of your project. And then try to build your project again. It works well in my side. – Mr Qian May 01 '20 at 04:31
  • And if possible, you can share a reproducible code sample with us to troubleshoot your issue. – Mr Qian May 01 '20 at 04:31
  • Actually, when you install the latest version of the `GMock` by nuget, you should not configure its library path into `Include Directories`, and all the files are already into External Dependencies in the solution Explorer. Or please check if you have still configure the old Gmock path under `Include Directories` and any others. If so, please delete it. – Mr Qian May 01 '20 at 06:10

2 Answers2

0

If you're using one of the pre-compiled NuGet packages (like the ones from Microsoft), then you have to make sure that its binaries are compatible with your project and VS. It sounds like the NuGet package you're using was built with a different VS version.

Last time I checked, some of the pre-built ones didn't even contain the gMock part of the framework, but that may have changed by now.

The better way is to use one of the NuGet packages that is not pre-built, such as the ones from Google. Just remove your current NuGet package and add the one from Google.

NOTE: If you want to put gMock in a separate library project, it can be more complicated. I wrote up a question/answer after discovering how non-obvious it was to do that. See answer here.

Chris Olsen
  • 3,243
  • 1
  • 27
  • 41
0

Suppression State Error LNK2038 mismatch detected for '_MSC_VER': value '1800' doesn't match value '1900' in GoogleTest.obj Test

I wonder if your project is migrated from other old VS version into VS2019.

1) If so, first,you should delete the old gmock library path which you used before under Include Directories(Right-click on project-->Properties-->VC++ Directories), Additional Include Directories(Properties-->C/C++-->General), Additional Dependencies(Properties-->Linker-->Input).

2) Second, install the nuget package gmock 1.10.0 by Right-click on your project-->Manage Nuget Package--> search gmock 1.10.0 and install it.

enter image description here

3) Right-click on your project-->Properties-->Configuration Properties-->General-->make sure Toolset Plarform is VS2019 v142.

4) close VS Instance, enter your project location and delete any Debug and Release folder and then restart your project and build again.

In addition, or you can try to create a new c++ project in VS2019 , install the latest gmock nuget package in your new project and then migrate your old project into the new project and test again.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41