首页 > 其他分享 >bazel test 编译失败:googletest、gtest 报错

bazel test 编译失败:googletest、gtest 报错

时间:2023-08-06 17:45:59浏览次数:44  
标签:google googletest bazel gtest internal 报错 external include

问题描述

bazel test 遇到很多奇怪的编译错误,报错位置位于“googletest”目录,而且没有修改过 googletest 源码:

ERROR: /bazel_cache/output_user_root/.../external/google/BUILD.bazel:80:11: Compiling googletest/src/gtest-matchers.cc failed: (Exit 1): gcc failed: error executing command (from target @google//:gtest) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 34 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from external/google/googletest/include/gtest/gtest-printers.h:114,
                 from external/google/googletest/include/gtest/gtest-matchers.h:48,
                 from external/google/googletest/src/gtest-matchers.cc:35:
external/google/googletest/include/gtest/internal/gtest-internal.h:635:58: error: wrong number of template arguments (0, should be 1)
  635 |   typedef ::std::map<std::string, CodeLocation, std::less<>> RegisteredTestsMap;
      |                                                          ^
In file included from /usr/include/c++/9/memory:76,
                 from external/google/googletest/include/gtest/gtest-matchers.h:43,
                 from external/google/googletest/src/gtest-matchers.cc:35:
/usr/include/c++/9/bits/stl_function.h:381:12: note: provided for 'template<class _Tp> struct std::less'
  381 |     struct less : public binary_function<_Tp, _Tp, bool>
      |            ^~~~
In file included from external/google/googletest/include/gtest/gtest-printers.h:114,
                 from external/google/googletest/include/gtest/gtest-matchers.h:48,
                 from external/google/googletest/src/gtest-matchers.cc:35:
external/google/googletest/include/gtest/internal/gtest-internal.h:635:59: error: template argument 3 is invalid
  635 |   typedef ::std::map<std::string, CodeLocation, std::less<>> RegisteredTestsMap;
      |                                                           ^~
external/google/googletest/include/gtest/internal/gtest-internal.h: In member function 'bool testing::internal::TypedTestSuitePState::AddTestName(const char*, int, const char*, const char*)':
external/google/googletest/include/gtest/internal/gtest-internal.h:612:23: error: request for member 'insert' in '((testing::internal::TypedTestSuitePState*)this)->testing::internal::TypedTestSuitePState::registered_tests_', which is of non-class type 'testing::internal::TypedTestSuitePState::RegisteredTestsMap' {aka 'int'}
  612 |     registered_tests_.insert(
      |                       ^~~~~~
external/google/googletest/include/gtest/internal/gtest-internal.h: In member function 'bool testing::internal::TypedTestSuitePState::TestExists(const string&) const':
external/google/googletest/include/gtest/internal/gtest-internal.h:618:30: error: request for member 'count' in '((const testing::internal::TypedTestSuitePState*)this)->testing::internal::TypedTestSuitePState::registered_tests_', which is of non-class type 'const RegisteredTestsMap' {aka 'const int'}
  618 |     return registered_tests_.count(test_name) > 0;
      |                              ^~~~~
external/google/googletest/include/gtest/internal/gtest-internal.h: In member function 'const testing::internal::CodeLocation& testing::internal::TypedTestSuitePState::GetCodeLocation(const string&) const':
external/google/googletest/include/gtest/internal/gtest-internal.h:622:40: error: qualified-id in declaration before 'it'
  622 |     RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
      |                                        ^~
In file included from external/google/googletest/include/gtest/internal/gtest-internal.h:42,
                 from external/google/googletest/include/gtest/gtest-printers.h:114,
                 from external/google/googletest/include/gtest/gtest-matchers.h:48,
                 from external/google/googletest/src/gtest-matchers.cc:35:
external/google/googletest/include/gtest/internal/gtest-internal.h:623:5: error: 'it' was not declared in this scope; did you mean 'int'?
  623 |     GTEST_CHECK_(it != registered_tests_.end());
      |     ^~~~~~~~~~~~
external/google/googletest/include/gtest/internal/gtest-internal.h:623:5: error: request for member 'end' in '((const testing::internal::TypedTestSuitePState*)this)->testing::internal::TypedTestSuitePState::registered_tests_', which is of non-class type 'const RegisteredTestsMap' {aka 'const int'}
  623 |     GTEST_CHECK_(it != registered_tests_.end());
      |     ^~~~~~~~~~~~
In file included from external/google/googletest/include/gtest/gtest-printers.h:114,
                 from external/google/googletest/include/gtest/gtest-matchers.h:48,
                 from external/google/googletest/src/gtest-matchers.cc:35:
external/google/googletest/include/gtest/internal/gtest-internal.h:624:12: error: 'it' was not declared in this scope; did you mean 'int'?
  624 |     return it->second;
      |            ^~
      |            int

问题分析

出现这个问题多半是因为没有启用 C++14 支持。即使你在 BUILD 文件中 cc_test 的 copts 里指定过 C++14,依然会出现该问题!

解决方案

bazel test 命令中增加 --cxxopt=-std=c++14 选项

bazel test --cxxopt=-std=c++14 //my_components/tests:my_test

标签:google,googletest,bazel,gtest,internal,报错,external,include
From: https://www.cnblogs.com/tengzijian/p/17609657.html

相关文章

  • bazel 使用 gtest/gmock 报错 Constraints from @bazel_tools//platforms have been r
    问题描述运行bazeltest命令,遇到错误:“Constraintsfrom@bazel_tools//platformshavebeenremoved.Pleaseuseconstraintsfrom@platformsrepositoryembeddedinBazel,orpreferablydeclaredependencyonhttps://github.com/bazelbuild/platforms.Seehttps://gi......
  • Bazel 如何生成 clangd/clang-tidy 所需的 compile_commands.json
    VSCode中如何使用clang-tidy安装clangd插件禁用ms-cpp插件(VSCode会自动提示有冲突)生成clangd所需的compile_commands.json文件如何生成compile_commands.json文件修改WORKSPACE,添加以下内容load("@bazel_tools//tools/build_defs/repo:http.bzl","http_a......
  • tensorflow 版本不同 报错合集
    1、"AttributeError:module'tensorflow'hasnoattribute'random_normal'"问题解决办法使用importtensorflow.compat.v1astftf.disable_v2_behavior()替换importtensorflowastf 2、tensorflow.python.framework.errors_impl.InvalidArgume......
  • vue 开源项目 安装脚手架报错问题 ERESOLVE unable to resolve dependency tree
       在安装项目依赖时,很大可能会遇到安装不成功的问题,其中有一个很大的原因,可能就是因为你的npm版本导致的 使用--force或--legacy-peer-deps可解决这种情况。--force会无视冲突,并强制获取远端npm库资源,当有资源冲突时覆盖掉原先的版本。--legacy-peer-deps标志是在v7......
  • 解决 Dapper.Contrib 报错“值对于 Int32 太大或太小”问题
    需求:在使用Dapper.Contrib执行Insert方法的时候,插入单条数据对于自增主键字段的返回值为插入后的值,当返回值大于2147483647的时候,Dapper.Contrib会抛出异常“值对于Int32太大或太小”问题。使用Dapper.Contrib插入数据的时候,报错“值对于Int32太大或太小”,此时数据库......
  • CentOS8安装Docker报错问题解决
    问题描述CentOS版本:8.5.2111。#cat/etc/redhat-releaseCentOSLinuxrelease8.5.2111安装准备:#安装所需软件包sudoyuminstall-yyum-utilsdevice-mapper-persistent-datalvm2#设置docker仓库:推荐阿里云sudoyum-config-manager--add-repohttp://mirrors.al......
  • nvidia-docker启动容器报错 Unknown runtime specified nvidia
    使用nvidia-docker创建容器时报错:Errorresponsefromdaemon:Unknownruntimespecifiednvidia.See'dockerrun--help'.主要原因在于配置docker镜像时,daemon.json文件被修改了。只要添加对应内容即可。vim /etc/docker/daemon.json原文件:{"registry-mirr......
  • ssm项目没添加lib目录的依赖导致页面404且没有任何报错
    问题:创建了一个ssm框架的模板,然后写了一个测试页面,页面404显示不出来且无任何报错。因为是个测试页面,只到controller层,检查半天web.xml和spring-controller.xml这两个配置文件都没啥问题,里面的视图解析器也没问题。关键这还不报错,然后在controller的方法中写一个后台输出,也没有输......
  • vue-table-width-grid 以及axios下载时报错
    importVuefrom'vue'importAppfrom'./App.vue'importrouterfrom'./router'importstorefrom'./store'//导入字体图标import'./assets/fonts/iconfont.css'importElementUIfrom'element-ui'impor......
  • 台达伺服电机(Delta ASDA - B3 - E)报错解决方式
    一硬件设备三台台达伺服驱动器(DeltaASDA-B3-E)树莓派4B伺服电机型号(ECM-B3M-CA0604RS1),输入2.4A110V,输出0.4KW1.27N.M3000r/min 二DeltaASDA-B3-E常见报错解决方式1恢复出厂设置(绝大部分报错都可以用以下方式处理)  P2.008修改数值为10断电重启2AL......