问题描述

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. css中的字体样式

    一.字体的样式 font-style:"normal" 正常 font-style:"italic"斜体 二.字体的粗细 font-weight:"b ...

  2. FreeRTOS 中的调度算法

    FreeRTOS 中的调度算法 01 调度算法概述 调度算法的作用: 实时系统的调度需求 相应时间要求 任务优先级 资源利用率 FreeRTOS 调度算法的目标 提供可预测的任务调度 实现任务的优先级 ...

  3. 洛谷 P9518 queue

    一眼模拟. 需要维护的东西可以根据操作求得: start:正在玩游戏的 \(1\) 或 \(2\) 个人: arrive:当前在排队但没玩游戏的队列.每个人是否在排队.游玩: leave:每个人是否在 ...

  4. Python:利用math和random模块实现RSA加密算法

    实验五报告: 利用math和random模块实现RSA加密算法 实验目标 本实验的主要目标是熟悉RSA(Rivest-Shamir-Adleman)密码算法的编写,其中包括求最大公因子.模逆的扩展欧几 ...

  5. Chromium 通过IDL方式添加扩展API

    基于chromium103版本 1. 自定义扩展API接口 chromium默认扩展api接口中有chrome.runtime.*,和chrome.send.*等,现在我们就仿照chrome.runt ...

  6. C++ 与 QML 之间进行数据交互的几种方法

    一.属性绑定 这是最简单的方式,可以在QML中直接绑定C++ 对象的属性.通过在C++ 对象中使用Q_PROPERTY宏定义属性,然后在QML中使用绑定语法将属性与QML元素关联起来. person. ...

  7. 全局关闭Unity编译的CS警告

    实现方式 Editor和Game的全局CSharp编译配置文件名: Assets/mcs.rsp 添加如下内容可屏蔽对应的警告信息 -nowarn:1234 常用内容 CS0219 未使用的publi ...

  8. ORACLE SQL语句逻辑读高优化案例

    川川找我优化SQL,逻辑读达到398,000,安排一下. SQL和执行计划: SELECT t1.*, t3.bed_number, t3.patient_name, t4.name FROM odw ...

  9. Go 14周年

    原文在这里. 由 Russ Cox, for the Go team 发布于2023年11月10日 今天,我们庆祝Go开源发布的第十四个生日!Go在过去一年里取得了巨大的进展,发布了两个功能丰富的版本 ...

  10. 基于Python下MySQL数据库驱动

    由于MySQL服务器以独立的进程运行,并通过网络对外服务,所以,需要支持Python的MySQL驱动来连接到MySQL服务器. 1.mysql-connector-python ​ mysql-con ...