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
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:
Clean the project before building it for other scheme. It may take a long time though.
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?