Has anyone successfully built gmock and gtest in Visual Studio 2010? I've tried with version 1.5.0, but I only get incomprehensible compilation errors.
I found this thread in google groups about issues found when building gmock-1.5.0 under VS2010. Following the thread, I've created a short readme file, which worked for me, so here it is:
- Download gmock 1.5.0 from Google Mock.
- Extract to library folder on the machine (e.g. C:\Libs\gmock-1.5.0). From now on, this folder will be reffered as 'GMOCK_ROOT'.
- Open VS2010, and load the solution: GMOCK_ROOT\msvc\gmock.sln. Let VS convert it from VS2008 to VS2010. Important! DO NOT double-click the solution file under GMOCK_ROOT\msvc. This resulted in a bad conversion.
Perform the following changes to sources according to the thread:
in project gmock --> Private Header Files --> gmock-internal-utils.h:
- lines 201, 202: comment out the 'Helper' functions:
char Helper(To);
static char (&Helper(...))[2]; // NOLINT
- lines 210-219: replace the entire
#ifdef..#endif
section with:
static const bool value = std::is_convertible<From, To>::value;
in project gmock_test --> Source Files --> gmock-printers_test.cc, line 848: perform an explicit casting of the NULL argument to
void*
, otherwise VS will automatically regard it is a null int. The resulting line should look like this:t10(false, 'a', 3, 4, 5, 1.5F, -2.5, str, static_cast<void*>(NULL), "10");
- Build the solution. This should result in 4 warnings, which, as described below, are (probably) OK.
Hope this helps,
Boaz
VS2010 compiler warnings from step 5 (see remarks at the end):
Warning 1 warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility 2227 1
Warning 2 warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility 2227 1
Warning 4 warning C4413: 'std::tr1::_Cons_node<_Car,_Cdr>::_Value' : reference member is initialized to a temporary that doesn't persist after the constructor exits C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\tuple 137 1
Warning 3 warning C4373: 'testing::gmock_generated_function_mockers_test::MockFoo::TakesConst': virtual function overrides 'testing::gmock_generated_function_mockers_test::FooInterface::TakesConst', previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers C:\Libs\gmock-1.5.0\test\gmock-generated-function-mockers_test.cc 133 1
Remarks regarding warnings:
- Warnings 1,2 are about Copy() in xutility being deprecated due to safty. As the mock library is not a part of the production release, this is OK by me.
- Warning 4 is OK according to the thread.
- Warning 3: not sure, but all seems to work well.
if anyone has a problem building the gmock solution itself, that is can’t generate the .lib files, this did it for me (vs 2015):
https://groups.google.com/forum/#!topic/googlemock/FaEAHedxpAQ
gmock_config.props contains an outdated definition of GTestDir:
<GTestDir>../../gtest</GTestDir>
Replace it with
<GTestDir>../../../googletest</GTestDir>
and you should get past your error.
At least the libs were compiled, i still got the gmock_test error though, despite the change suggested there.
来源:https://stackoverflow.com/questions/3141835/googlemock-and-googletest-in-visual-studio-2010