问题描述

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

bazel test 编译失败:googletest、gtest 报错的更多相关文章

  1. LINUX下编译安装PHP各种报错大集合

    本文为大家整理汇总了一些linux下编译安装php各种报错大集合 ,感兴趣的同学参考下. nginx1.6.2-mysql5.5.32二进制,php安装报错解决: 123456 [root@clien ...

  2. 运行编译后的程序报错 error while loading shared libraries: lib*.so: cannot open shared object file: No such file or directory

    运行编译后的程序报错  error while loading shared libraries: lib*.so: cannot open shared object file: No such f ...

  3. Heka 编译安装后 运行报错 panic: runtime error: cgo argument has Go pointer to Go pointer

    Heka 编译安装后 运行报错 panic: runtime error: cgo argument has Go pointer to Go pointer 解决办法: 1.  Start heka ...

  4. Xcode 编译运行旧项目报错解决之路

    运行几年前做的项目,发现各种编译报错,一个一个解决记录下: 1.Xcode(Xcode9)编译运行报错,但是在 issue navigatior 栏看不到错误信息: 解决方案:在 show repor ...

  5. 编译nginx的时候报错 需要安装PCRE

    ./configure --prefix=/mynginx/ 本地编译nginx的时候 报错 提示需要安装PCRE 错误信息: ./configure: error: the HTTP rewrite ...

  6. VS项目中使用Nuget还原包后编译生产还一直报错?

    Nuget官网下载Nuget项目包的命令地址:https://www.nuget.org/packages 今天就遇到一个比较奇葩的问题,折腾了很久终于搞定了: 问题是这样的:我的解决方案原本是好好的 ...

  7. 编译lua5.3.2报错提示libreadline.so存在未定义的引用解决方法

    从官网上下载5.3.2的源码后,make linux进行编译,提示报错: gcc -std=gnu99 -o lua lua.o liblua.a -lm -Wl,-E -ldl -lreadline ...

  8. 编译时.test文件报错无法解决的方法,关闭test编译

    有几次遇到从网上下载到的iOS开源代码编译报错,报错位置为Test Target的源文件,我就挺奇怪我又没做测试为啥会编译Test Target的源文件,之前的暴力解决方法是把Test Target直 ...

  9. 我的Android进阶之旅------>解决Android Studio编译后安装apk报错:The APK file does not exist on disk

    1.错误描述 今天用Android Studio编译应用后安装APK的时候,报错了,错误如下所示: The APK file build\outputs\apk\OYP_2.3.4_I2Base_64 ...

  10. g++ 6.4编译opencv-2.4.10报错记录

      fetch公司的项目进行编译,此项目依赖opencv库.由于本人一直比较偏爱fedora,但也因此给我带来了许多"乐趣"(麻烦).fedora一直走得比较前沿,g++ 6.3了 ...

随机推荐

  1. c语言代码练习3改进

    #define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> int main() { int x = 0; printf("请输入一 ...

  2. umich cv-2-1

    UMICH CV Linear Classifiers 对于使用线性分类器来进行图片分类,我们可以给出这样的参数化方法: 而对于这样一个式子,我们怎么去理解呢? 首先从代数的角度,这个f(x,W)就是 ...

  3. 程序员必备:使用AI工具通义千问,没有广告没有假链接,比搜索引擎要便捷多了,回答还算满意

    我提的问题是:使用Python连接Oracle,cx_Oracle和oracledb那个效率更高,功能更全,请列出他们的区别和实例代码 回复是: 以下是使用Python连接Oracle时,cx_Ora ...

  4. Android应用中对于微信分享的实例及问题

    源码地址 如何分享 分享无相应 分享结果如何接收响应 微信 分享回调 (提示几点关键问题:   debug_key 一定要获得对应的签名码 然后和weixin官网的appid对应     ) 几点注意 ...

  5. Blackmail

    Blackmail Arthur Hailey The chief house officer, Ogilvie, who had declared he would appear at the Cr ...

  6. 11. 用Rust手把手编写一个wmproxy(代理,内网穿透等), 实现健康检查

    11. 用Rust手把手编写一个wmproxy(代理,内网穿透等), 实现健康检查 项目 ++wmproxy++ gite: https://gitee.com/tickbh/wmproxy gith ...

  7. mybtis-plus 出现 Wrong namespace

    今天进行项目整合,刚开始代码搬的还挺快乐的,但是到后面调试起来,头晕眼花的.记录一个基本的错误. Cause: org.apache.ibatis.builder.BuilderException:  ...

  8. Kubernetes:kube-apiserver 之鉴权

    kubernetes:kube-apiserver 系列文章: Kubernetes:kube-apiserver 之 scheme(一) Kubernetes:kube-apiserver 之 sc ...

  9. GitHub - 如何对开源项目做出贡献

    GitHub - 对项目做出贡献 转载来自git官方教程:https://git-scm.com/book/zh/v2/GitHub-对项目做出贡献 对项目做出贡献 账户已经建立好了,现在我们来了解一 ...

  10. Neural Networks投稿要求总结

    自用,NN投稿要求,相关的部分的中文版翻译,原文链接:https://www.sciencedirect.com/journal/neural-networks/publish/guide-for-a ...