[CMake] OSX Bundle Generator for Cpack

Benjamin Reed rangerrick at gmail.com
Fri Jun 6 14:09:41 EDT 2008


On Fri, Jun 6, 2008 at 1:44 PM, Sean McBride <sean at rogue-research.com> wrote:

>>One thing I would recommend, DYLD_LIBRARY_PATH should be considered
>>harmful except for very specific uses.
>
> Benjamin is probably referring to:
> <http://docs.info.apple.com/article.html?artnum=305509>

That too, but...

The majority of people who use DYLD_LIBRARY_PATH are using it because
they're used to LD_LIBRARY_PATH on other platforms, and it has a very
different and nonintuitive behavior on OSX which isn't immediately
obvious until you hit the bizarre corner-cases.  It short-circuits a
number of things dyld normally does in the course of finding dynamic
libraries (essentially treating namespaced twolevel libraries as flat,
among other things), and tends to have weird side-effects.  Not as big
of a deal when used just for a single application wrapper script, as
in this case, but if it spawns other processes which were linked
against other versions of libraries, things can potentially get messy.

It's generally best to use install_name_tool -change to fix your
app-bundle'd binaries to explicitly look for a library in a given
place inside it's resource bundle.

For example, for a bundle like this:

  Foo.app/
  Foo.app/Contents/
  Foo.app/Contents/MacOS
  Foo.app/Contents/MacOS/Foo
  Foo.app/Contents/Resources/
  Foo.app/Contents/Resources/libprivatelib.dylib
  Foo.app/Contents/Frameworks/
  Foo.app/Contents/Frameworks/Bar.framework/
  ...

...instead of having a script that wraps around "Foo" and sets
DYLD_LIBRARY_PATH, you should use install_name_tool to tell Foo where
to find stuff:

  install_name_tool -change
/Library/Frameworks/Bar.framework/Versions/A/Bar
@executable_path/../Frameworks/Bar.framework/Versions/A/Bar
  install_name_tool -change /usr/local/lib/libprivatelib.dylib
@executable_path/../Resources/libprivatelib.dylib

DYLD_LIBRARY_PATH (as well as the other DYLD_* env vars) has real
uses, but is best to discourage it's use unless you know what you're
doing.  =)

But, I digress.  ;)

The patch looks good to me, it's nice to have some more control over
what happens in the app bundles.

-- 
Benjamin Reed a.k.a. Ranger Rick
Fink, KDE, and Mac OS X development
http://www.raccoonfink.com/


More information about the CMake mailing list