Xcode集成Google-Mobile-Ads-SDK后报Undefined symbol: _main链接错误求助
问题
使用Xcode 15.4创建新iOS项目,未引入CocoaPods时可在iPhone 15模拟器正常编译。执行pod init创建Podfile后,将项目目标iOS版本改为12.0并添加pod 'Google-Mobile-Ads-SDK',执行pod install --repo-update后重新编译,出现以下链接错误:
ld: 警告:Could not find or use auto-linked framework 'CoreAudioTypes': framework 'CoreAudioTypes' not found
架构arm64下的未定义符号:"_main", referenced from:
ld: 架构arm64下找不到符号
clang: error: linker command failed with exit code 1 (use -v to see invocation)
解决方案
打开正确的项目文件:执行
pod install后必须打开项目的.xcworkspace文件,而非原来的.xcodeproj,否则Xcode无法识别Pods依赖的框架和配置。修复
_main未定义问题:- 检查主界面配置:进入项目Target → General → Deployment Info,确认Main Interface已设置为项目的主Storyboard(如
Main),空值会导致找不到入口main函数。 - 确认编译目标类型:检查Target的Build Settings → Packaging → Product Type,确保值为
Application,Framework类型无main函数入口。 - 清理编译缓存:按
Cmd+Shift+K清理项目缓存,再按Cmd+Option+Shift+K清理DerivedData,之后重新编译。
- 检查主界面配置:进入项目Target → General → Deployment Info,确认Main Interface已设置为项目的主Storyboard(如
解决CoreAudioTypes框架缺失问题:
- 手动添加框架:进入项目Target → Build Phases → Link Binary With Libraries,点击
+搜索CoreAudioTypes.framework并添加,设置为Optional以兼容低版本iOS。 - 指定兼容的SDK版本:在Podfile中改为
pod 'Google-Mobile-Ads-SDK', '~> 9.0'(9.x版本为支持iOS12的最后几个大版本),执行pod update更新依赖。 - 检查框架搜索路径:进入Target的Build Settings → Search Paths → Framework Search Paths,添加
$(inherited)以继承Pods配置的路径,确保Xcode能找到依赖框架。
- 手动添加框架:进入项目Target → Build Phases → Link Binary With Libraries,点击
内容的提问来源于stack exchange,提问作者Raii
相关产品推荐
相关产品推荐

