ios 命名空间“std”中没有名为“unary_function”的模板;你是说“__unary_function”吗?

xesrikrc  于 12个月前  发布在  iOS
关注(0)|答案(9)|浏览(706)

我刚把Xcode升级到15.0,突然它开始在RCT_Folly中给我以下错误
No template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?
这是它失败的地方:
结构hash_base:std::unary_function<T,std::size_t> {};
我尝试删除缓存数据和派生数据并清理构建。已尝试删除Pod和node_modules。但没有任何帮助。

x8diyxa7

x8diyxa71#

在我的例子中,我在构建失败后遵循了Xcode的建议。我只是点击了“修复”,现在一切都很好。
我希望它能在下次更新中得到修复。

c90pui9n

c90pui9n2#

在源文件中修复这个问题之前,最好的选择是在您的podfile中添加已删除的libcpp函数,如此处所解决的。https://github.com/facebook/react-native/issues/37748#issuecomment-1580589448

post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
        end
      end
  end
y1aodyip

y1aodyip3#

这有点傻,但我通过像XCode建议的那样放置__unary_function来解决它。
所以实际上这条线应该是...
结构hash_base:std::_unary_function<T,std::size_t> {};

cwdobuhd

cwdobuhd4#

我在运行npx react-native run-ios后在终端中得到了这个错误。我通过以下步骤解决了这个问题:
1.打开Xcode
1.点击播放图标启动模拟器
1.模拟器会失败,但Xcode会在侧边栏中显示错误。单击错误以查看错误在代码中的位置。
1.点击按钮“修复”
1.完成!现在模拟器将成功运行。

ecr0jaav

ecr0jaav5#

所有库必须更新其代码以使用std::function & std::bind而不是unary_function
解决方法
选择Pod> Build Settings > In section Apple Clang - Preprocessing > under Macro section

添加到发布&调试-> _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
ps:要添加这个只需点击列然后点击“+”在底部->然后粘贴:_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION

szqfcxe2

szqfcxe26#

@Ash是对的,我把我的Xcode和iOS版本更新到17.0,一切都很好,但是当我在iOS 17上运行它时,我得到了这个错误。

No template named 'unary_function' in namespace 'std'; did you mean '__unary_function'

我按照提供的步骤修复它,应用程序开始运行。然而,当我打开Map屏幕时,它崩溃了,这是使用react-native-maps。之后,我删除了pod,重新安装了节点模块,但同样的问题仍然存在。令人惊讶的是,当我将以下代码添加到我的Podfile并重新安装Pod时,应用程序开始正常工作。你得把两者都修好

post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
        end
      end
  end
bhmjp9jg

bhmjp9jg7#

似乎有另一种解决方法
https://github.com/facebook/react-native/issues/37748#issuecomment-1580334650

9gm1akwq

9gm1akwq8#

对于任何遇到此错误的React Native用户,Facebook已经在v0.72.5 -release notes中发布了修复程序。
XCode 15修复(21763 e85 e3,0 dbd 621 c59 & 8a 5 b2 d 6735)
npm update react-native

vmjh9lq9

vmjh9lq99#

如果你仍然有一个旧的RN版本,
这对我很有效:

post_install do |installer|
        react_native_post_install(installer)
        __apply_Xcode_12_5_M1_post_install_workaround(installer)
        
        installer.pods_project.build_configurations.each do |config|
            installer.pods_project.targets.each do |target|
                if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle"
                    config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
                end
            end
    
            # Set the preprocessing macro for the whole Pods project
            existing_flags = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
            existing_flags << '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION'
            config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = existing_flags
        end
    end

相关问题