【问题标题】:googletest and VS2010: cannot use EXPECT_EQgoogletest 和 VS2010:不能使用 EXPECT_EQ
【发布时间】:2012-04-27 20:13:45
【问题描述】:

我已将一个项目转换为 VS2010。它包括一个基于 googletest 的单元测试项目。当我使用宏 EXPECT_EQ 时,出现以下链接器错误:

LNK2019:未解析的外部符号“类 testing::internal::String __cdecl testing::internal::StrStreamToString(class std::basic_stringstream,class std::allocator > *)" (?StrStreamToString@internal@testing@@YA? AVString@12@PAV?$basic_stringstream@DU?$char_traits@D@std@@V? $allocator@D@2@@std@@@Z) 在函数“public:class”中引用 testing::internal::String __thiscall testing::Message::GetString(void)const " (? GetString@Message@testing@@QBE?AVString@internal@2@XZ)

当我使用EXPECT_TRUE 时,一切正常。有人知道这个问题吗?

谢谢

【问题讨论】:

  • 能否为您的 EXPECT_EQ 语句提供一个代码示例?

标签: visual-studio visual-c++ googletest


【解决方案1】:

EXPECT_EQ 尝试将您的数据值转换为字符串以供显示; EXPECT_TRUE 没有。

如果没有看到您的代码,您似乎正在测试一种用户类型,此功能可以编译但未链接,即未实现。

这是一个常见问题。如果 EXPECT_TRUE 有效,您可能只想坚持下去。

【讨论】:

  • 这只是咬了我几个小时。我所拥有的是模板专业化:template <typename T> struct is_thing { static const bool value = false; }; template <> struct is_thing<MyType> { static const bool value = true; };,然后我试图做EXPECT_EQ(is_thing<SomeType>::value, false); 并得到一个链接器错误。 EXPECT_FALSE(is_thing<SomeType>::value); 可以按照您的建议正常工作。你能解释一下有什么区别/为什么会这样吗?
  • @DavidDoria:最好提出一个适当的问题并发布相关代码。如果你愿意,可以在评论中链接到它。
猜你喜欢
  • 2022-06-10
  • 1970-01-01
  • 2011-02-03
  • 1970-01-01
  • 2021-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-27
相关资源
最近更新 更多