3

I have a framework that is being used in my application, plus a few XPC services contained inside the application bundle. How can I link all the bundles to the single copy of the framework contained inside the application's Frameworks folder (vs copying the framework to every bundle)? All of the services and the application are sandboxed, so I'm not sure if the XPC services would be able to access the Framework in the main app bundle as it would be outside of the sandbox.

indragie
  • 18,002
  • 16
  • 95
  • 164

2 Answers2

4

Have you had a look at @rpath? This all assumes that you can change the build-settings for the framework (requires targeting OS X 10.5 or newer).

  1. Set the frameworks install path and name.
    • INSTALL_PATH = @rpath
    • LD_DYLIB_INSTALL_NAME = @rpath/$(PRODUCT_NAME).$(WRAPPER_EXTENSION)/$(PRODUCT_NAME)
  2. Set the app’s and XPC’s runpath search paths so that the framework is included.
    • For the app: LD_RUNPATH_SEARCH_PATHS = @loader_path/../Frameworks/
    • For the XPC service: LD_RUNPATH_SEARCH_PATHS = @loader_path/../../../../Frameworks
    • The runpath search paths can be set to multiple values if needed.

For more on @rpath see Dave Dribin’s post “Using @rpath: Why and How” and Mike Ash’s Friday Q&A “Linking and Install Names”.

Edit: I’ve used this myself for a few projects and it works.

rastersize
  • 488
  • 3
  • 19
  • Setting the Runpath Search Paths is what I tried initially, but it doesn't seem to work when set on the XPC service (I get a dyld linking error when the service is started). However, manually fixing the library path using `install_name_tool` did the trick (see my above answer). Thanks :) – indragie Jan 17 '13 at 01:20
2

This is possible using install_name_tool. Example:

install_name_tool -change @executable_path/../Frameworks/MyFramework.framework/Versions/A/MyFramework @executable_path/../../../../Frameworks/MyFramework.framework/Versions/A/MyFramework "$BUILT_PRODUCTS_DIR/MyApp.app/Contents/XPCServices/com.me.MyApp.SomeXPC.xpc/Contents/MacOS/com.me.MyApp.SomeXPC"

More information here.

indragie
  • 18,002
  • 16
  • 95
  • 164