多项目工作区下dyld: Library not loaded问题求助
dyld: Library not loaded Error with CocoaPods & Multi-Project Workspace Hey there, let's work through this dyld: Library not loaded error you're facing with your StepikIOS workspace. This is a common issue when using CocoaPods with multiple Xcode projects in a workspace, so let's break down the fixes step by step:
1. First, Fix Your Truncated Podfile
Your provided Podfile cuts off at target :Exte...—this is likely a root cause. You need to ensure every target in your two Xcode projects is properly linked to the pods you've defined. Here's how to structure it correctly:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '10.0' use_frameworks! workspace 'StepikIOS' xcodeproj 'Common/StepikCore/StepikCore.xcodeproj' xcodeproj 'Features/ExternalWorkers/ExternalWorkers.xcodeproj' def net_pods pod 'Alamofire', '~> 4.7.2' end # Link pods to StepikCore target target 'StepikCore' do xcodeproj 'Common/StepikCore/StepikCore.xcodeproj' net_pods end # Link pods to ExternalWorkers target target 'ExternalWorkers' do xcodeproj 'Features/ExternalWorkers/ExternalWorkers.xcodeproj' net_pods end
Replace the target names with the actual target names from each .xcodeproj if they differ.
2. Reset CocoaPods Installation
Corrupted Pod installations or outdated caches often cause this error. Run these commands in your project root:
- Delete existing Pod artifacts:
rm -rf Podfile.lock Pods/ - Update your CocoaPods repo and reinstall:
pod install --repo-update - Critical: Always open
StepikIOS.workspace(not individual .xcodeproj files) after this step.
3. Verify Build Settings Inheritance
Ensure your targets inherit CocoaPods' search paths:
- Open your workspace in Xcode.
- Select a target (e.g., StepikCore) and go to Build Settings.
- Search for
Framework Search Paths—add$(inherited)and${PODS_ROOT}/Alamofire(set torecursive). - Search for
Library Search Paths—add$(inherited)if it's missing.
4. Check Framework Embedding
Since you're using use_frameworks!, dynamic frameworks need to be embedded in your app:
- Go to your target's General tab.
- Scroll to
Frameworks, Libraries, and Embedded Content. - For every CocoaPods framework (like Alamofire), set the embed option to Embed & Sign.
5. Clean Project & Simulator Caches
Stale build artifacts can cause linking issues:
- In Xcode: Press
Cmd+Shift+Kto clean the project, thenCmd+Option+Shift+Kto clean the build folder. - In the iPhone Simulator: Go to
Device > Erase All Content and Settings, then quit and restart the simulator.
6. Remove Manual Framework References
If you manually added any pod frameworks (like Alamofire) to your projects before using CocoaPods, delete them—duplicate references will cause conflicts.
If you've tried all these steps and still see the error, double-check that your target names in the Podfile exactly match the target names in each .xcodeproj (case-sensitive!).
内容的提问来源于stack exchange,提问作者Nick

