【问题标题】:ld: framework not found Alamofireld:找不到框架 Alamofire
【发布时间】:2026-01-24 01:30:01
【问题描述】:

我花了几天时间试图解决这个问题,但现在我的想法已经不多了。

我有:
Xcode v8.2.1
苹果 Swift 版本 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
cocoapods-1.2.0

我正在创建新的 Xcode 项目(单视图应用程序),选择干净并构建 - 一切都像魅力一样工作。

在根项目路径中的 pod init 之后,我正在编辑我的 Podfile,如下所示:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target 'test' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
    pod 'Alamofire', '~> 4.4'

  # Pods for test

end

现在,当我尝试清理和重建应用程序时,出现构建错误,如下所示:

d /Users/Dawid/Library/Developer/Xcode/DerivedData/test-auxygswgvxhnqfamjqqncqxaieqk/Build/Products/Debug-iphonesimulator/test.app/test normal x86_64
    cd /Users/Dawid/xCode/test
    export IPHONEOS_DEPLOYMENT_TARGET=10.2
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.2.sdk -L/Users/Dawid/Library/Developer/Xcode/DerivedData/test-auxygswgvxhnqfamjqqncqxaieqk/Build/Products/Debug-iphonesimulator -F/Users/Dawid/Library/Developer/Xcode/DerivedData/test-auxygswgvxhnqfamjqqncqxaieqk/Build/Products/Debug-iphonesimulator -F/Users/Dawid/Library/Developer/Xcode/DerivedData/test-auxygswgvxhnqfamjqqncqxaieqk/Build/Products/Debug-iphonesimulator/Alamofire -filelist /Users/Dawid/Library/Developer/Xcode/DerivedData/test-auxygswgvxhnqfamjqqncqxaieqk/Build/Intermediates/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/test.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=10.2 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/Dawid/Library/Developer/Xcode/DerivedData/test-auxygswgvxhnqfamjqqncqxaieqk/Build/Intermediates/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/test_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/Dawid/Library/Developer/Xcode/DerivedData/test-auxygswgvxhnqfamjqqncqxaieqk/Build/Intermediates/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/test.swiftmodule -framework Alamofire -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/Dawid/Library/Developer/Xcode/DerivedData/test-auxygswgvxhnqfamjqqncqxaieqk/Build/Intermediates/test.build/Debug-iphonesimulator/test.build/test.app.xcent -framework Pods_test -Xlinker -dependency_info -Xlinker /Users/Dawid/Library/Developer/Xcode/DerivedData/test-auxygswgvxhnqfamjqqncqxaieqk/Build/Intermediates/test.build/Debug-iphonesimulator/test.build/Objects-normal/x86_64/test_dependency_info.dat -o /Users/Dawid/Library/Developer/Xcode/DerivedData/test-auxygswgvxhnqfamjqqncqxaieqk/Build/Products/Debug-iphonesimulator/test.app/test

ld: warning: directory not found for option '-F/Users/Dawid/Library/Developer/Xcode/DerivedData/test-auxygswgvxhnqfamjqqncqxaieqk/Build/Products/Debug-iphonesimulator/Alamofire'
ld: framework not found Alamofire
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我尝试编辑 $(inherited) 的框架搜索路径,清理项目,重新打开 Xcode,尝试新副本,下载以前版本的 Alamofire 以及我在网上找到的所有内容,但到目前为止没有任何效果。

编辑:
添加了概述打印屏幕

编辑 2: 在@Jagdeep 建议之后,现在我有不同的错误(附加打印屏幕):

【问题讨论】:

  • 您能否提供您的 Xcode 项目概览屏幕的屏幕截图?您在左窗格中单击蓝色 xcode 项目的位置。
  • 好的,已添加
  • 哦,哇,谢谢,但我讨厌痛苦!您可以通过左上角的按钮展开该视图的左窗格吗?我要找的资料在那里!我怀疑我知道问题出在哪里,但想确认...

标签: ios xcode cocoapods alamofire


【解决方案1】:

试着去你的

Target>Build Setting>Build Active Architecture Only

设置

  • 用于调试

  • 发布

确保你有所有目标的配置相同 也在你的

Pods>Build Setting>Build Active Architecture Only

保持相同的值

清理和构建 希望有效

【讨论】:

  • 检查 Build Phases 下的框架 -> Link Binary With Libraries -> 并选择 alamofire.framework。
  • 确保您打开的是工作区而不是项目文件,然后尝试安装 pod 并更新 pod
  • 我已经在打开工作区,但看起来 pod update 完成了这项工作。还有一个问题 - 我现在收到警告“ld:警告:找不到选项'-F/Users/Dawid/xCode/test/build/Debug-iphoneos'的目录”知道为什么吗?
  • 打开项目文件而不是工作区是我的问题。谢谢@Jagdeep
【解决方案2】:

当您第一次使用pod install 时,您将收到这条重要信息:

[!] Please close any current Xcode sessions and use `Project.xcworkspace` for this project from now on.

这意味着你已经退出 Xcode,然后每次你想处理你的项目时打开 Project.xcworkspace 文件。

【讨论】: