在 Linux 中使用 g++ 编译器编译 {fmt} 包含文件时,出现类是私有的且无法从外部访问的错误

问题描述 投票:0回答:1

我正在使用 #include 在我的 C++ 应用程序中格式化 std::array

#include <fmt/ranges.h>

#include <array>

int main()
{
    std::array<short unsigned int, 3> arr = {1, 2, 3};
    fmt::print("{}", arr);
}

它在 Windows 和 Macos 中可以正确编译,但在使用 g++ 编译器的 Linux 中失败,并出现以下错误:

../externals/fmtlib/fmt/ranges.h:49:29:错误:类“fmt::v10::detail::is_std_string_like”中的所有成员函数都是私有的 [-Werror=ctor-dtor-privacy] 模板类 is_std_string_like {

../externals/fmtlib/fmt/ranges.h:65:29:错误:类“fmt::v10::detail::is_map”中的所有成员函数都是私有的[-Werror=ctor-dtor-privacy]

模板类 is_map {

../externals/fmtlib/fmt/ranges.h:49:29:错误:类“fmt::v10::detail::is_std_string_like”中的所有成员函数都是私有的 [-Werror=ctor-dtor-privacy] 模板类 is_std_string_like {

../externals/fmtlib/fmt/ranges.h:65:29:错误:类“fmt::v10::detail::is_map”中的所有成员函数都是私有的[-Werror=ctor-dtor-privacy]

模板类 is_map {

截至撰写本文时,MSVC 和 Clang 是仅有的 2 个支持该标头的编译器。 g++不支持吗

看来 MSVC 和 Clang 是唯一支持此标头的 2 个编译器 。并且 g++ 不支持此标头。

请帮助我。

c++ c++11 c++17 g++ fmt
1个回答
1
投票

问题是您选择的

-Werror=ctor-dtor-privacy
会拒绝有效的 C++ 代码,解决方案是从构建标志中删除此标志,至少在编译
fmt/ranges.h
时如此。

© www.soinside.com 2019 - 2024. All rights reserved.