Xcode 26.4构建时报错:在React Native的 iOS构建中,调用consteval函数 'fmt::basic_format_string' 不是常量表达式
我在使用Xcode 26.4编译React Native iOS项目时遇到了构建错误。
环境
- React Native: 0.81.x
- Xcode: 26.4
- macOS: 26.4
错误
在构建过程中,我遇到了以下错误:
call to consteval function 'fmt::basic_format_string' is not a constant expression
期望行为
该项目在iOS上应无构建错误地编译并运行。
实际行为
在上述错误的影响下,编译失败。
复现步骤
- 创建或打开一个React Native项目
- 安装依赖(npm install / yarn)
- 在Xcode 26.4中打开iOS项目
- 尝试构建该项目
- 在编译期间出现错误
我尝试过
- 清理构建文件夹
- 删除DerivedData
- 重新安装node_modules
- 再次执行pod install
- 多次尝试重新构建
Xcode 26.4中这类错误的根本原因是什么,如何在一个React Native的 iOS项目中解决?
解决方案
针对Xcode 26.4的 C++20构建错误在React Native中的修复方案
Xcode 26.4的新编译器改变了对C++20特性的处理方式。现在它不再接受React Native中较旧的 {fmt} 库在编译时验证字符串的方式。
最简单的修复方法是强制 fmt 库使用 C++17 而不是C++20。由于 consteval 在C++17中不存在,编译器就不会再发出警告,构建也会成功。
将以下内容添加到你的 ios/Podfile 内的 post_install 块中:
post_install do |installer|
# Keep your existing react_native_post_install here
react_native_post_install(installer, config[:reactNativePath])
# Fix for Xcode 26.4 build error
installer.pods_project.targets.each do |target|
if target.name == 'fmt'
target.build_configurations.each do |config|
config.build_settings['CLANG_CXX_LANGUAGE_STANDARD'] = 'c++17'
end
end
end
end
为何有效: 我们只针对 fmt 库进行处理。你不应该把整個项目改成C++17,因为React Native的其他部分实际上需要C++20才能运行。
应用方法:
- 保存
Podfile。 - 在你的终端中运行
pod install。 - 在Xcode中清理构建并再次运行。
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。