MacOS Sonoma下React Native Expo项目pod install报错:无法运行C编译程序
问题场景
项目框架:React Native(Expo托管)
运行环境:MacOS Sonoma 14.5、XCode 15.4、M2 Pro芯片
执行pod install时在ios目录报错,sqlite3编译阶段configure提示无法运行C编译程序,完整错误日志:
⚠️ Something went wrong running
pod installin theiosdirectory.
Commandpod installfailed.
└─ Cause: /bin/bash -c
set -e
cd sqlite-src-3450300
./configure
make sqlite3.c sqlite3.h sqlite3ext.hchecking build system type... arm-apple-darwin23.5.0
checking host system type... arm-apple-darwin23.5.0
checking for gcc... clang
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling...
configure: error: in/Users/datachanturia/Library/Caches/CocoaPods/Pods/Release/sqlite3/3.45.3+1-02d1f/sqlite-src-3450300': configure: error: cannot run C compiled programs. If you meant to cross compile, use--host'.
See `config.log' for more detailspod install --repo-update --ansi exited with non-zero code: 1
解决方案
1. 修复Xcode命令行工具配置
- 确认命令行工具路径:
xcode-select --print-path - 若路径不是
/Applications/Xcode.app/Contents/Developer,执行切换:sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer - 重新同意Xcode许可协议:
sudo xcodebuild -license accept
2. 关闭终端Rosetta模式(M系列芯片)
- 找到终端应用,右键选择「显示简介」
- 取消勾选「使用Rosetta打开」,重启终端
- 重新进入ios目录执行
pod install
3. 清除CocoaPods缓存并重试
- 删除sqlite3指定版本缓存:
rm -rf ~/Library/Caches/CocoaPods/Pods/Release/sqlite3/3.45.3+1-02d1f - 清除全局缓存:
pod cache clean --all - 重新执行安装:
cd ios pod install --repo-update
4. 在Podfile中强制指定sqlite3构建参数
在ios目录的Podfile中添加以下配置,跳过交叉编译检查:
pre_install do |installer| installer.pod_targets.each do |target| if target.name == 'sqlite3' target.build_configurations.each do |config| config.build_settings['CLANG_ENABLE_MODULES'] = 'NO' config.build_settings['OTHER_CFLAGS'] = '-arch arm64' end end end end
保存后重新执行pod install
5. 升级CocoaPods版本
- 检查当前版本:
pod --version - 若版本低于1.15.0,执行升级:
sudo gem install cocoapods
内容的提问来源于stack exchange,提问作者David Chanturia

