Search code examples
iosxcodexcode-project

Why does my Xcode project compile only when it's in a workspace?


I have an Xcode project P2 which is part of a workspace where I have another project P1.

When I build P1, it creates a Cocoa Touch Framework. In P2, I have added the framework created by P1 by going to General-->Link Frameworks and Libraries-->Select P1.framework.

Then I build the P2 project and it compiles successfully with the P1.framework integrated in it. So, all good with this.

Now instead of opening the workspace and building the P2 project from workspace, I directly open the P2 project by clicking p2.xcodeproj file. I can see the p1.framework file in it.

But, now when I try to build P2, it gives error:

framework not found P1. clang: error: linker command failed with exit code 1 (use -v to see invocation).

Can anyone help me to understand why P2 gives error when directly opened from p2.xcodeproj file?


Solution

  • For the p1.framework to be linkable properly, the project where p1.framework is referenced from must be visible.

    This is probably because you initially used the standard Xcode UI to choose the p1.framework from the P1 project in your workspace. Xcode doesn't directly reference p1.framework, but rather via the P1 project. This is useful, because it allows you to modify P1 as much as you like (changing the build destinations, etc.) and yet allows other projects to use the p1.framework.

    An easier analogy might be to think of folder aliases. It's like you reference a file via a folder alias, and then you delete that folder. Naturally, errors appear.