关于 <typeinfo> 在 boost 库上使用的编译错误 配置重现步骤研究步骤

如何解决关于 <typeinfo> 在 boost 库上使用的编译错误 配置重现步骤研究步骤

当我将我的项目从 c++11 迁移到 c++17 时,项目的构建失败了,并出现了一些关于使用的错误。我怀疑是 boost 库,因为我得到的错误是指与 boost 库相关的类。我在下面分享有关编译错误的所有细节。

配置

  • 增强版:1.73.0
  • 所选架构:

    enter image description here

  • Xcode 版本:版本 12.4 (12D4e)
  • 苹果叮当声

重现步骤

  1. 设置 C++ 语言辩证为 C++17[-std=c++17] :

    enter image description here

  2. 删除派生数据文件
  3. 清理缓存
  4. 清理构建文件
  5. Pod 更新
  6. 构建开始
  7. 构建失败:“您需要在使用 'typeid' 运算符之前包括在内”

错误列表:

1.stl_type_index.hpp 第 90 行错误

inline stl_type_index() BOOST_NOEXCEPT
   : data_(&typeid(void))//You need to include <typeinfo> before using the 'typeid' operator
{}

2.stl_typ_index.hpp 第 246 行错误

    template <class T>
inline stl_type_index stl_type_index::type_id() BOOST_NOEXCEPT {
    typedef BOOST_DEDUCED_TYPENAME boost::remove_reference<T>::type no_ref_t;
    typedef BOOST_DEDUCED_TYPENAME boost::remove_cv<no_ref_t>::type no_cvr_prefinal_t;

    #  if (defined(__EDG_VERSION__) && __EDG_VERSION__ < 245) \
        || (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 744)

        // Old EDG-based compilers seem to mistakenly distinguish 'integral' from 'signed integral'
        // in typeid() expressions. Full template specialization for 'integral' fixes that issue:
        typedef BOOST_DEDUCED_TYPENAME boost::conditional<
            boost::is_signed<no_cvr_prefinal_t>::value,boost::make_signed<no_cvr_prefinal_t>,boost::type_identity<no_cvr_prefinal_t>
        >::type no_cvr_prefinal_lazy_t;

        typedef BOOST_DEDUCED_TYPENAME no_cvr_prefinal_t::type no_cvr_t;
    #else
        typedef no_cvr_prefinal_t no_cvr_t;
    #endif

    return typeid(no_cvr_t); // You need to include <typeinfo> before using the 'typeid' operator
}
  1. stl_type_index.hpp 第 261 行出错
    template <class T>
    inline stl_type_index stl_type_index::type_id_with_cvr() BOOST_NOEXCEPT {
        typedef BOOST_DEDUCED_TYPENAME boost::conditional<
            boost::is_reference<T>::value ||  boost::is_const<T>::value || boost::is_volatile<T>::value,detail::cvr_saver<T>,T >::type type;
    
        return typeid(type);//You need to include <typeinfo> before using the 'typeid' operator
    }
  1. stl_type_index 第 270 行出错
    #ifdef BOOST_NO_RTTI
        return value.boost_type_index_type_id_runtime_();
    #else
        return typeid(value); // You need to include <typeinfo> before using the 'typeid' operator
    #endif
  1. sp_counted_impl 第 178 和 183 行中的错误
    virtual void * get_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT
    {
        return ti == BOOST_SP_TYPEID_(D)? &reinterpret_cast<char&>( del ): 0; // You need to include <typeinfo> before using the 'typeid' operator
    }

    virtual void * get_local_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT
    {
        return ti == BOOST_SP_TYPEID_(D)? boost::detail::get_local_deleter( boost::addressof( del ) ): 0; // You need to include <typeinfo> before using the 'typeid' operator
    }
  1. shared_ptr.hpp 行 1011 中的错误
template<class D,class T> D * basic_get_deleter( shared_ptr<T> const & p ) BOOST_SP_NOEXCEPT
{
    return static_cast<D *>( p._internal_get_deleter(BOOST_SP_TYPEID_(D)) ); // You need to include <typeinfo> before using the 'typeid' operator
}
  1. shared_ptr.hpp 第 1168 和 1173 行中的错误
template<class D,class T> D * basic_get_local_deleter( D *,shared_ptr<T> const & p ) BOOST_SP_NOEXCEPT
{
    return static_cast<D *>( p._internal_get_local_deleter( BOOST_SP_TYPEID_(local_sp_deleter<D>) ) ); //You need to include <typeinfo> before using the 'typeid' operator
}

template<class D,class T> D const * basic_get_local_deleter( D const *,shared_ptr<T> const & p ) BOOST_SP_NOEXCEPT
{
    return static_cast<D *>( p._internal_get_local_deleter( BOOST_SP_TYPEID_(local_sp_deleter<D>) ) ); //You need to include <typeinfo> before using the 'typeid' operator
}

研究步骤

  1. 更新提升版本。我应用了以下文章中建议的两种 boost 编译方法
  2. 清理 ccache,清理构建文件夹,删除 Xcode 派生数据,然后在应用每个解决方案后开始构建
  3. 构建失败。编译器错误与较旧的错误相同。 您对包含问题有什么建议吗?感谢您的帮助和时间。

解决方法

https://en.cppreference.com/w/cpp/language/typeid

在使用 <typeinfo> 之前必须包含标头 typeid

哪些标准包括哪些其他标准未指定并且可以随任何更新而更改。因此,您之前 <typeinfo> 被其他东西拖入了,而现在您没有。

这似乎是错误消息告诉您的(带尖括号的文件名已从降价中删除,但作为您稍后显示的注释可见)。您需要在到达导致错误的代码之前包含此标头。明白吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?