CocoaPods + Fix for can’t Archive: ld: library not found for -lPods
I just recently learned about the excellent CocoaPods tool for easily adding open-source iOS libraries to your projects, and managing their versions. CocoaPods is basically like Ruby’s Gemfiles for iOS. If you’ve ever fought with Xcode and setting up library paths, static libraries, etc. this is a much easier way to do it. The documentation is simple and useful.
Example for how to install AFNetworking:
$ pod search AFNetworking
--> AFNetworking (0.5.1, 0.7.0, 0.9.0, 0.9.1, 0.9.2, 0.10.0, 1.0RC1) A delightful iOS and OS X networking framework. - Homepage: https://github.com/AFNetworking/AFNetworking - Source: https://github.com/AFNetworking/AFNetworking.git
Create a file called Podfile with the following:
platform :ios pod 'AFNetworking', '1.0RC1'
# You could just do: pod 'AFNetworking' if you are happy to get the latest version
Then to install it:
$ pod install
You’re done! CocoaPods will generate an .xcworkspace for you that contains your project, plus a Pods.xcodeproj that contains all of the libraries specified in your Podfile. I found this to be an amazingly simple, elegant way to handle dependencies. It’s easy to allow upgrades to new versions of libraries if you want, or lock them down to a certain range.
I had one further gotcha – I could properly build my app for both Simulator and Device, but I was unable to Archive. I would get the following linker error:
ld: library not found for -lPods
I saw a lot of discussion of this error on the internet, but none of the fixes worked for me. I didn’t have custom build configurations or anything like that. I stumbled across the fix accidentally. The problem was that my project had originally been targeted for iOS 4.2 and up, so I had my VALID_ARCHS setting on “armv6 armv7”, but I had since upgraded my minimum deployment target to 4.3, meaning armv7 is all that’s required. This didn’t harm my project itself, but the CocoaPods generated Pods.xcodeproj was set for only armv7 and there was a mismatch when linking. Switching my app project’s VALID_ARCHS to just “Standard (armv7)” fixed this linker error for me, and I was able to Archive properly.