May 2004

Embedding Frameworks in Applications

If your Mac OS X application uses a framework, you can embed it in your application even after you’ve built and linked the application against a framework which you’ve installed privately to /Library/Frameworks.

The secret is to use the obscure install_name_tool command. You’ll need to do two things:

  1. Change the identification name of the framework itself from Foo.framework/... to @executable_path/../Frameworks/Foo.framework/...
  2. Change the application’s main executable dependent shared library list, from Foo.framework/... to @executable_path/../Frameworks/Foo.framework/...

Here’s how to do it:

  1. Copy your existing framework first and work on that: the install_name_tool command directly modifies the framework, so you’ll probably want be operating on a copy of it.
  2. Run install_name_tool -id '@executable_path/../Frameworks/Foo.framework/...' Foo.framework/Foo
  3. Run install_name_tool -change 'Foo.framework/...' '@executable_path/../Frameworks/Foo.framework/...'

To find out what to put in the ... bit of the commands above, run the otool -L command on the executable or shared library to see the full pathname. It should look something like Versions/A/Foo.

It’s a bit of a pain in the arse, but at least it works. Until I figured this out, it was really a bit of a pain to embed frameworks into applications properly!