【问题标题】:How can I use GoogleMock in jenkins?如何在詹金斯中使用 GoogleMock?
【发布时间】:2015-06-02 16:22:12
【问题描述】:

我在 CentOS 虚拟机上安装了 Jenkins。现在我想用模拟(谷歌模拟)运行单元测试(谷歌测试)。我尝试安装here 中描述的框架。 (在我的 lubuntu 机器上,使用这些步骤可以正常运行)

当我尝试构建时:

g++ -O2 -pthread -Werror -Wall -o unitTest DriveTest.cpp Drive.cpp PWM.cpp -lgtest -lgtest_main -lgmock

我收到以下错误:

 make unitTest
 g++ -O2 -std=c++0x -pthread -Werror -Wall -o unitTest DriveTest.cpp Drive.cpp PWM.cpp -lgtest -lgtest_main -lgmock
 In file included from /usr/include/gmock/gmock-spec-builders.h:75,
                  from /usr/include/gmock/gmock-generated-function-mockers.h:43,
                  from /usr/include/gmock/gmock.h:61,
                  from PWMMock.h:4,
                  from DriveTest.cpp:1:
 /usr/include/gmock/gmock-matchers.h:1485: sorry, unimplemented: cannot expand ‘Tail ...’ into a fixed-length argument list
 /usr/include/gmock/gmock-matchers.h:1486: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1486: error: ‘ListType’ in class ‘int’ does not name a type
 /usr/include/gmock/gmock-matchers.h:1486: error: template argument 2 is invalid
 /usr/include/gmock/gmock-matchers.h:1486: error: expected ‘::’ before ‘ListType’
 /usr/include/gmock/gmock-matchers.h: In static member function ‘static int testing::internal::MatcherList<kSize, Head,
 Tail>::BuildList(const Head&, const Tail& ...)’:
 /usr/include/gmock/gmock-matchers.h:1493: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1493: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1493: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1493: error: ‘BuildList’ is not a member of ‘int’
 /usr/include/gmock/gmock-matchers.h: In static member function ‘static testing::Matcher<T> testing::internal::MatcherList<kSize,
 Head, Tail>::CreateMatcher(const int&)’:
 /usr/include/gmock/gmock-matchers.h:1503: error: request for member ‘first’ in ‘matchers’, which is of non-class type ‘const int’
 /usr/include/gmock/gmock-matchers.h:1504: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1504: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1504: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1504: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1504: error: ‘int’ is not a class type
 /usr/include/gmock/gmock-matchers.h:1504: error: ‘CreateMatcher’ is not a member of ‘int’
 ...

我该如何解决这个问题?

【问题讨论】:

  • CentOS 机器上的 GCC 是什么版本,你的 Lubuntu 机器上是什么版本的 GCC?
  • @sjdowling lubuntu 的 gcc 版本为 4.8.2,CentOS 的 gcc 版本为 4.4.7。

标签: c++ gcc jenkins centos googlemock


【解决方案1】:

您在 CentOS 上的 GCC 版本似乎太旧,无法处理这些可变参数模板。我希望 4.4.7 可以使用它们,因为 the status page 似乎表明它们应该可用。不过this question 似乎证实了这种情况。

我的建议是使用dev-toolset 2 repo 升级编译器。这将使您可以访问 CentOS 6 上的 GCC 4.8(我猜您正在使用的是 GCC 版本),但使用经过修改的 stdlib,这意味着您的二进制文件仍将使用 CentOS/RedHat 5 的运行时运行。

【讨论】:

  • 我使用 dev-toolset 2 升级了 gcc。g++ -v 现在显示:gcc version 4.8.2 20140120 (Red Hat 4.8.2-15) (GCC) 我现在可以在 CentOS 中构建我的项目,而无需一个问题。但是 Jenkins 仍然显示同样的错误?
  • @RIPS10 Jenkins 是使用 gcc 4.8 还是旧的 4.4?您可能需要在 Jenkins 构建脚本的顶部添加 source /opt/rh/devtoolset-2/enable 行,以确保将环境切换为使用新工具链。
  • 谢谢,Jenkins 不知何故仍在使用旧的编译器。额外的行解决了我的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-21
  • 1970-01-01
  • 1970-01-01
  • 2020-03-30
  • 2017-09-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多