Visual Studio 2010 中的 GoogleMock 和 GoogleTest

发布于 2024-09-08 01:14:23 字数 81 浏览 5 评论 0 原文

有人在 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

书间行客 2024-09-15 01:14:23

我找到了这个帖子 在关于在 VS2010 下构建 gmock-1.5.0 时发现的问题的 google 小组中。按照线程,我创建了一个简短的自述文件,该文件对我有用,所以这里是:

  • Google 模拟
  • 解压到机器上的库文件夹(例如C:\Libs\gmock-1.5.0)。从现在开始,该文件夹将被称为“GMOCK_ROOT”。
  • 打开VS2010,加载解决方案:GMOCK_ROOT\msvc\gmock.sln。让VS将其从VS2008转换为VS2010。 重要!请勿双击 GMOCK_ROOT\msvc 下的解决方案文件。 这会导致转换失败。
  • 根据线程

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

      • 第 201、202 行:注释掉“Helper”函数:

      char Helper(To);

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

      • 第 210-219 行:将整个 #ifdef..#endif 部分替换为:

      static const bool value = std::is_convertible::value;

    • 在项目 gmock_test 中 -->源文件 --> gmock-printers_test.cc,第 848 行:
      执行将 NULL 参数显式转换为 void*,否则 VS 将自动将其视为 null int。结果行应如下所示:

      t10(false, 'a', 3, 4, 5, 1.5F, -2.5, str, static_cast(NULL), "10");

    • 构建解决方案。这应该会导致 4 条警告,如下所述,这些警告(可能)是正常的。

希望这会有所帮助,

Boaz


VS2010 编译器从步骤 5 发出的警告(请参阅最后的注释):

警告 1 警告 C4996:
'std::_Copy_impl':函数调用
可能不安全的参数 - this
调用依赖于调用者来检查
传递的值是正确的。到
禁用此警告,使用
-D_SCL_SECURE_NO_WARNINGS。请参阅有关如何使用 Visual C++ 的文档
“检查迭代器”C:\Program Files
(x86)\微软 Visual Studio
10.0\VC\include\xutility 2227 1

警告 2 警告 C4996:
'std::_Copy_impl':函数调用
可能不安全的参数 - this
调用依赖于调用者来检查
传递的值是正确的。到
禁用此警告,使用
-D_SCL_SECURE_NO_WARNINGS。请参阅有关如何使用 Visual C++ 的文档
“检查迭代器”C:\Program Files
(x86)\微软 Visual Studio
10.0\VC\include\xutility 2227 1

警告 4 警告 C4413:
'std::tr1::_Cons_node<_Car,_Cdr>::_Value'
:引用成员被初始化为
暂时的,之后不会持续存在
构造函数退出 C:\Program Files
(x86)\微软 Visual Studio
10.0\VC\include\tuple 137 1

警告 3 警告 C4373:
'测试::gmock_generate_function_mockers_test::MockFoo::TakesConst':
虚函数重写
'测试::gmock_ generated_function_mockers_test::FooInterface::TakesConst',
以前版本的编译器做了
仅当参数时不覆盖
因常量/易失性而异
限定符 C:\Libs\gmock-1.5.0\test\gmock- generated-function-mockers_test.cc 133 1

关于警告的备注:

  1. 警告 1,2 是关于 xutility 中的 Copy() 由于安全原因而被弃用。由于模拟库不是生产版本的一部分,因此我认为这是可以的。
  2. 根据,警告 4 是可以的线程
  3. 警告 3:不确定,但一切似乎都运行良好。

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

      1. 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:

  1. 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.
  2. Warning 4 is OK according to the thread.
  3. Warning 3: not sure, but all seems to work well.
千秋岁 2024-09-15 01:14:23

如果有人在构建 gmock 解决方案本身时遇到问题,即无法生成 .lib 文件,这对我来说是这样(与 2015 年相比):

https://groups.google.com/forum/#!topic/googlemock/FaEAHedxpAQ

gmock_config.props 包含 GTestDir 的过时定义:
../../gtest

将其替换为 ../../../googletest 即可
应该可以克服你的错误。

至少库已编译,尽管建议进行更改,但我仍然收到 gmock_test 错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文