React Native 0.73中fmt编译失败的问题求助
React Native 0.73中fmt编译失败的问题求助
看起来你在React Native 0.73项目里遇到了fmt库的编译报错,我之前折腾RN项目时也碰到过类似的C++库编译问题,给你几个实际可行的排查和解决思路:
先把你遇到的错误信息贴出来方便对照:
The following build commands failed: CompileC /Users/daviduriololivares/Library/Developer/Xcode/DerivedData/appPacientes-frvutsfymsghspbycxmmxvehxbzl/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/fmt.build/Objects-normal/arm64/format.o /Users/daviduriololivares/Documents/test/app-pacientes/ios/Pods/fmt/src/format.cc normal arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'fmt' from project 'Pods') Building workspace appPacientes with scheme appPa
先清缓存!这是最常见的解决办法:
- 直接删除Xcode的DerivedData文件夹(就是错误日志里那个长路径的文件夹),手动删或者在Xcode里通过
File > Project Settings > Derived Data打开文件夹删除; - 切换到项目的ios目录,执行
pod deintegrate彻底移除现有pod依赖; - 执行
pod cache clean --all清空pod的本地缓存; - 最后重新执行
pod install,再回到Xcode或者用npx react-native run-ios尝试编译。
- 直接删除Xcode的DerivedData文件夹(就是错误日志里那个长路径的文件夹),手动删或者在Xcode里通过
检查Xcode版本是否达标:
React Native 0.73官方要求使用Xcode 14.3及以上版本,如果你用的是更低版本,很可能会因为对C++新标准的支持不足,导致fmt库编译失败。建议升级Xcode到符合要求的稳定版本。强制指定fmt的C++编译标准:
打开项目ios目录下的Podfile,在post_install钩子中添加针对fmt的编译配置,强制使用兼容的C++标准:post_install do |installer| installer.pods_project.targets.each do |target| if target.name == 'fmt' target.build_configurations.each do |config| # 强制使用C++17标准 config.build_settings['CLANG_CXX_LANGUAGE_STANDARD'] = 'c++17' # 指定使用libc++库 config.build_settings['CLANG_CXX_LIBRARY'] = 'libc++' end end end end修改完Podfile后,重新执行
pod install,再尝试编译项目。确认项目架构设置:
打开Xcode项目,选中你的主target,进入Build Settings标签页,搜索Architectures:- 确保
Architectures设置为Standard Architectures (arm64, x86_64); - 针对模拟器的话,检查
Excluded Architectures里是否错误排除了arm64(如果是M系列芯片的Mac,模拟器需要arm64架构支持)。
- 确保
如果以上方法都试过还是不行,可以把完整的编译错误日志(包括更多的报错细节,比如具体的语法错误提示)贴出来,这样能更精准地定位问题~
内容来源于stack exchange
相关产品推荐
相关产品推荐

