Visual Studio 2010中的GoogleMock和GoogleTest [英] GoogleMock and GoogleTest in Visual Studio 2010

查看:125
本文介绍了Visual Studio 2010中的GoogleMock和GoogleTest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人在Visual Studio 2010中成功构建gmock和gtest吗?我已经尝试过使用1.5.0版,但是我只会遇到难以理解的编译错误.

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:

  • Google Mock 下载gmock 1.5.0.
  • 解压缩到计算机上的库文件夹(例如C:\ Libs \ gmock-1.5.0).从现在开始,该文件夹将被简称为"GMOCK_ROOT".
  • 打开VS2010,并加载解决方案:GMOCK_ROOT \ msvc \ gmock.sln.让VS将其从VS2008转换为VS2010. 重要!不要双击GMOCK_ROOT \ msvc下的解决方案文件.这会导致转换错误.
  • 根据

  • 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:

  • 在项目gmock中->专用头文件-> gmock-internal-utils.h:

  • in project gmock --> Private Header Files --> gmock-internal-utils.h:

  • 第201、202行:注释掉"Helper"功能:

char Helper(To);

static char (&Helper(...))[2]; // NOLINT

  • 第210-219行:将整个#ifdef..#endif部分替换为:
  • lines 210-219: replace the entire #ifdef..#endif section with:

static const bool value = std::is_convertible<From, To>::value;

,行848: 对NULL参数执行显式强制转换为void*,否则VS将自动将其视为null整数.结果行应如下所示:

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");

  1. 构建解决方案.这将导致4条警告,如下所述(可能)正常.

希望这会有所帮助,

Boaz

第5步中的VS2010编译器警告(请参阅最后的注释):

VS2010 compiler warnings from step 5 (see remarks at the end):

警告1警告C4996: 'std :: _ Copy_impl':函数调用 可能不安全的参数-此 呼叫取决于呼叫者进行检查 传递的值是正确的.到 禁用此警告,使用 -D_SCL_SECURE_NO_WARNINGS.请参阅有关如何使用Visual C ++的文档 'Checked Iterators'C:\ Program文件 (x86)\ Microsoft Visual Studio 10.0 \ VC \ include \ xutility 2227 1

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

警告2警告C4996: 'std :: _ Copy_impl':函数调用 可能不安全的参数-此 呼叫取决于呼叫者进行检查 传递的值是正确的.到 禁用此警告,使用 -D_SCL_SECURE_NO_WARNINGS.请参阅有关如何使用Visual C ++的文档 'Checked Iterators'C:\ Program文件 (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

警告4警告C4413: 'std :: tr1 :: __ Cons_node< _Car,_Cdr> :: _ Value' :引用成员初始化为 此后不会持续的临时 构造函数退出C:\ Program Files (x86)\ Microsoft Visual Studio 10.0 \ VC \ include \ tuple 137 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

警告3警告C4373: '测试:: gmock_generated_function_mockers_test :: MockFoo :: TakesConst': 虚函数覆盖 'testing :: gmock_generation_function_mockers_test :: FooInterface :: TakesConst', 以前版本的编译器做了 仅在参数时不覆盖 区别于const/volatile 限定词C:\ Libs \ gmock-1.5.0 \ test \ gmock-generated-function-mockers_test.cc 133 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

关于警告的注释:

  1. 警告1,2是关于由于安全性而弃用xutility中的Copy().由于模拟库不是生产版本的一部分,所以我可以.
  2. 根据 查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆