KISS

Keep It Simple Stupid

CocoaPods and iOS-Universal-framework in the same project

| comments

Updated on 2012-10-10: A follow-up article is here: continuation.

In one of the projects for iOS I’m working on I use CocoaPods to manage external dependencies and a project based on iOS-Universal-framework to build a C++ component as a static library. That is, I have an Xcode workspace with 3 projects: the main one, the library one, and Pods with other dependencies. It all works great except for one thing: I build the project for iOS devices, then build it for simulators, then build for devices again, and here build fails with linking errors:

1
2
3
4
5
6
7
ld: warning: ignoring file ~/Library/Developer/Xcode/DerivedData/proj-aghrequilhjyjydjjzsvybqpxbuq/Build/Products/Debug-iphoneos/libPods.a,
file was built for archive which is not the architecture being linked (armv7):
~/Library/Developer/Xcode/DerivedData/proj-aghrequilhjyjydjjzsvybqpxbuq/Build/Products/Debug-iphoneos/libPods.a
Undefined symbols for architecture armv7:
  "_OBJC_CLASS_$_DDFileLogger", referenced from:
      objc-class-ref in AppDelegate.o

These symbols are from external libraries and exported by the Pods project. In a clean project, which uses CocoaPods, everything is fine. If I delete the framework project, the build process works great: no unnecessary rebuilds after switching schemes.

After some investigation, I found out that the framework project somehow triggered rebuilding the Pods project on every build, and moreover the libPods.a library had the wrong architecture for the target. In other words, when scheme is iOS Device, the library contains armv6 and armv7 architectures in both Debug-iphoneos and Debug-iphonesimulator directories, even though it should contain i386 in the latter file. Then, selecting the scheme for simulator, the both files contain armv6 and armv7 architectures. The third time the files aren’t being rebuilt. That’s why the linking errors show up.

I haven’t been able to fix the cause of the issue, but here are 2 solutions I’ve discovered:

  1. Clean the project before building it for other scheme. It may take a long time though.

  2. The issue seems to be somehow related to the way Xcode builds a workspace with dependencies. Go to Product > Edit Scheme… (⌘<), select Build on the left, and turn off Parallelize Builds option on the right:

This did the trick for me. I have this issue with Xcode 4.3.3 and 4.4, but the cause may be with the iOS-Universal-framework template.

I’d like to find out what’s exactly wrong there. Do you have any ideas?

iOS

Don't hesitate to leave a comment below. NB! If you don't see a comment form under the post, it's most likely that an extension (such as Ghostery, NoScript, or AdBlock) of your browser blocks the scripts from disqus.com, and you can unblock that.

« Ruby gem and proxy How big is your English vocabulary? »

Comments