【问题标题】:Compilation Error: googlegtest fails with compilation error编译错误:googlegtest 因编译错误而失败
【发布时间】:2021-04-29 09:00:22
【问题描述】:

我正在使用 googlegtest 进行测试,但在编译时出现错误。

/gtest-printers.h:389:55: error: no member named 'u8string' in namespace 'std' GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char8_t, ::std::u8string);

/home/googletest/googletest/include/gtest/gtest-printers.h:379:40: note: expanded from macro 'GTEST_IMPL_FORMAT_C_STRING_AS_STRING_' class FormatForComparison<CharType*, OtherStringType> {

/home/googletest/googletest/include/gtest/gtest-printers.h:390:61: error: no member named 'u8string' in namespace 'std' GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char8_t, ::std::u8string);

/home/googletest/googletest/include/gtest/gtest-printers.h:379:40: note: expanded from macro 'GTEST_IMPL_FORMAT_C_STRING_AS_STRING_' class FormatForComparison<CharType*, OtherStringType> {
生成了 2 个错误。`

这是宏的参数。

编译器版本:Clang++ 11.1.0

在 googletest 内编译可以工作,但是当包含为标头时,编译失败。无法找到错误的根本原因?

您能帮忙说明为什么链接会发生在 std 上吗?

make VERBOSE=1 输出:

VERBOSE Output

【问题讨论】:

  • 您是否在启用 C++20 模式的情况下进行构建? std::u8string 是 C++20 标准中的新功能,在 Clang 11 中可能默认未启用。
  • 设置 CXX_FLAGS=-std=c++20 后没有运气
  • 尝试make VERBOSE=1并粘贴输出消息将有助于找到根本原因。
  • 我附上了详细输出的链接
  • @TheShmoo 尝试安装 sudo apt install libstdc++-11-dev libstdc++-11-doc

标签: c++ clang++


【解决方案1】:

原来是 gtest bug:在 gtest-printers.h 中使用了错误的功能检查宏。作为临时解决方法,您可以只编辑标题,在几个地方将 cpp_char8_t 替换为 __cpp_lib_char8_t:

#ifdef cpp_char8_t // <---- should be changed to __cpp_lib_char8_t
//...std::u8string usage...
#endif

【讨论】:

    猜你喜欢
    • 2014-02-08
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    • 2018-03-26
    • 1970-01-01
    • 2012-04-13
    • 2016-05-24
    相关资源
    最近更新 更多