views:

545

answers:

4

I have a custom framework that, following the advice in Apple's Framework Programming Guide >> Installing your framework I install in /Library/Frameworks. I do this by adding a Run Script build phase with the following script:

cp -R  build/Debug/MyFramework.framework /Library/Frameworks

In my projects I then link against /Library/Frameworks/MyFramework and import it in my classes like so:

#import <MyFramework/MyFramework.h>

This works very well, except that I always see the following message in my debugger console:

Loading program into debugger… sharedlibrary apply-load-rules all warning: Unable to read symbols for "/Users/elisevanlooij/Library/Frameworks/MyFramework.framework/Versions/A/MyFramework" (file not found). warning: Unable to read symbols from "MyFramework" (not yet mapped into memory). Program loaded.

Apparently, the compiler first looks in /Users/elisevanlooij/Library/Frameworks, can't find MyFramework, then looks in /Library/Frameworks, does find MyFramework and continues on its merry way. So far this has been more of an annoyance than a real problem, but when runnning unit tests, gdb stops on the (file not found) and refuses to continue. I have solved the problem by adding an extra line to the Run Script Phase

cp -R  build/Debug/MyFramework.framework ~/Library/Frameworks

but it feels like sello-taping something that shouldn't be broken in the first place. How can I fix this?

A: 

Naturally, when you distribute your framework it should be installed in /Library/Frameworks; however it seems odd to me that you're doing that with the test/debug versions of your framework.

My first instinct would be to install test versions under ~/Library, as it just makes setting up your test and debug environment that much simpler. If possible, I would expect the debug/test framework to be located in the build tree of the version I'm testing, in which case it's installed as a Private Framework for testing purposes. That would make your life much simpler when it comes time to deal with multiple versions of your framework.

Ultimately, it doesn't matter where the framework is located as long as your application or test suite loads the correct version. Choose the location that makes testing/debugging/development easiest.

Darren
Since the framework is used by several projects, installing it as a private framework is not feasible. I have tried the same thing with the release version (cp -R build/Release/MyFramework.framework /Library/Frameworks) but the result is the same.As for it not mattering where the framework is located as long as ... -- well, words fail me.
Elise van Looij
A: 

There's not much reason to put a framework into Library/Frameworks, and it's a lot of work: You'd need to either do it for the user in an Installer package, which is a tremendous hassle to create and maintain, or have installation code in your app (which could only install to ~/L/F, unless you expend the time and effort necessary to make your app capable of installing to /L/F with root powers).

Much more common is what Apple calls a “private framework”. You'll bundle this into your application bundle.

Even frameworks intended for general use by any applications (e.g., Sparkle, Growl) are, in practice, built to be used as private frameworks, simply because the “right” way of installing a single copy of the framework to Library/Frameworks is such a hassle.

Peter Hosey
I don't doubt that creating an installer package is a lot of work -- I've never done it and it's not something I look forward to. But since it will need to be done anyway for the apps, I can't see that adding one more for the framework would be such a big deal -- it probably should be bundled into the app installers anyway, unless it proves to be an uncommonly popular framework. All in all, I'm not convinced that keeping the framework private is that important.
Elise van Looij
+1  A: 

The conventional way to do this is to have your framework project and its clients share a common build directory. Xcode will search for framework headers and link against framework binaries in the build folder first, before any other location. So an app project that compiles and links against the header will pick up the most-recently-built one, rather than whatever's installed.

You can then remove the cp -r and instead use the Install Location build setting to place your build product in the final location, using xcodebuild install DSTROOT=/ at the command line. But you'll only need to do this when you're finished, not every time you rebuild the framework.

cdespinosa
Intriguing, but I found two problems with this approach. First of all, xcodebuild install DSTROOT=/ does cure the "Unable to read symbols" problem. However:1) When the build directory for the framework was pointed at the common build directory (outside the project folder), xcodebuild somehow would overlook changes made in the framework. The modified date of the framework header files would change, but not hte content(perhaps to do with versioning?).2) When I changed the build directory back to default build, xcodebuild would install inside the framework another copy of the framework. Weird.
Elise van Looij
+1  A: 

In the past months, I've learned a lot more about frameworks, so I'm rewriting this answer. Please note that I'm talking about installing a framework as part of the development workflow.

The preferred location for installing a public framework (i.e. a framework that will be used by more than one of your apps or bundles) is /Library/Frameworks[link text] because "frameworks in this location are discovered automatically by the compiler at compile time and the dynamic linker at runtime."[Framework Programming Guide]. The most elegant way to do this is in the Deployment section of the Build settings.

As you work on your framework, there are times when you do want to update the framework when you do a build, and times when you don't. For that reason, I change the Deployment settings only in the Release Configuration. So:

  1. Double-click on the framework target to bring up the Target info window and switch to the Build tab.
  2. Select Release in the Configuration selectbox.
  3. Scroll down to the Deployment section and enter the following values:

Deployment Location = YES (click the checkbox)

Installation Build Products Location = /

Installation Directory = /Library/Frameworks

The Installation Build Products Location serves as the root of the installation. Its default value is some /tmp directory: if you don't change it to the system root, you'll never see your installed framework since it's hiding in the /tmp.

Now you can work on your framework as you like in the Debug configuration without upsetting your other projects and when you are ready to publish all you need to do is switch to Release and do a Build.

Elise van Looij
You should consider any answers from cdespinosa regarding the Xcode build system to be authoritative.
NSResponder
Well, I voted up his answer, so I hope my kneecaps are safe. But I do consider the solution I arrived at more elegant, as it involves fewer changes to the default Xcode settings and eliminates the need for the command line.
Elise van Looij