You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Xcode 15.0后RCT_Folly报错:std中无unary_function模板

解决Xcode 15升级后RCT-Folly中std::unary_function不存在的报错

问题根源:Xcode 15搭载的LLVM编译器默认启用C17/20标准,其中std::unary_function已被正式移除(C17弃用,C++20删除),而旧版本的RCT-Folly仍在使用这个废弃的模板类。

以下是几种可行的解决方法:

方法1:升级React Native版本

直接将React Native升级到0.72.5及以上或0.73.x及更高版本,这些版本已经修复了RCT-Folly对C++新标准的兼容问题。升级后重新执行pod install即可。

方法2:手动修改RCT-Folly的源码

  1. 在项目Pods目录中找到RCT-Folly/folly/functional/Hash.h文件

  2. 定位到报错的代码行:

    struct hash_base : std::unary_function<T, std::size_t> {};
    
  3. 将其替换为:

    struct hash_base {};
    

    (std::unary_function仅用于定义参数和返回值的typedef,C++11及以后的语法不再依赖它,直接移除继承不影响功能)

    或者添加条件编译以兼容多版本:

    #if __cplusplus >= 202002L
    struct hash_base {};
    #else
    struct hash_base : std::unary_function<T, std::size_t> {};
    #endif
    

方法3:通过Podfile添加编译兼容配置

在项目的Podfile末尾添加以下post_install钩子,强制RCT-Folly使用C++17标准并屏蔽废弃警告:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'RCT-Folly'
      target.build_configurations.each do |config|
        config.build_settings['CLANG_CXX_LANGUAGE_STANDARD'] = 'c++17'
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= []
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].append('_LIBCPP_DISABLE_DEPRECATION_WARNINGS')
      end
    end
  end
end

修改后执行pod install重新安装依赖。

内容的提问来源于stack exchange,提问作者Mitesh Baraiya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 16:34:26