otool -L

Source: language agnostic – Is it OK to use DYLD_LIBRARY_PATH on Mac OS X? And, what’s the dynamic library search algorithm with it? – Stack Overflow

Note that otool -L tells you the libraries the executable is linked with not necessarily the ones that will actually be loaded when it is run. You can see this by setting DYLD_LIBRARY_PATH and running otool (the paths displayed for the libraries do not take DYLD_LIBRARY_PATH into account).
—————————————————————————-

For documentation on the dynamic link editor’s environment variables and how they affect the search for dynamic libraries, man dyld.

DYLD_LIBRARY_PATH

This is a colon separated list of directories that contain libraries. The dynamic linker searches these directories before it searches the default locations for libraries. It allows you to test new versions of existing libraries.

For each library that a program uses, the dynamic linker looks for it in each directory in DYLD_LIBRARY_PATH in turn. If it still can’t find the library, it then searches DYLD_FALLBACK_FRAMEWORK_PATH and DYLD_FALLBACK_LIBRARY_PATH in turn.

Use the -L option to otool(1). to discover the frameworks and shared libraries that the executable is linked against.

DYLD_FALLBACK_LIBRARY_PATH

This is a colon separated list of directories that contain libraries. It is used as the default location for libraries not found in their install path. By default, it is set to $(HOME)/lib:/usr/local/lib:/lib:/usr/lib.

DYLD_VERSIONED_LIBRARY_PATH

This is a colon separated list of directories that contain potential override libraries. The dynamic linker searches these directories for dynamic libraries. For each library found dyld looks at its LC_ID_DYLIB and gets the current_version and install name. Dyld then looks for the library at the install name path. Whichever has the larger current_version value will be used in the process whenever a dylib with that install name is required. This is similar to DYLD_LIBRARY_PATH except instead of always overriding, it only overrides is the supplied library is newer.

——————————————————————————————

As you’ve noted, DYLD_LIBRARY_PATH behaves like LD_LIBRARY_PATH on other *nix. However, there is another environment variable you should look at called DYLD_FALLBACK_LIBRARY_PATH.

In general, these are (both on osx and linux) suggested only for development use as they can cause symbol lookup errors when you override with a library that does not have the same symbol table. A good example of this is when you attempt to override the default install of VecLib (e.g. blas lapack) with a custom install. This will cause symbol not found errors in applications linked to the system VecLib if DYLD_LIBRARY_PATH is set and the reverse (symbol lookup errors in custom applications) if it is not. This is due to the system blas/lapack not being a full implementation of the ATLAS libs.

DYLD_FALLBACK_LIBRARY_PATH will not produce these problems.

When installing libraries to a non-standard location, DYLD_FALLBACK_LIBRARY_PATH is much more sane. This will look for symbols in libraries provided in the default paths and if the symbol is not found there, fall back to the specified path.

The benefit is that this process will not cause symbol lookup errors in applications compiled against the default libraries.

In general, when libraries are installed to non-standard locations absolute paths should be specified which negates the ambiguity of the dynamic lookup.

  • 3
    Another benefit – if you set DYLD_LIBRARY_PATH, X11 will refuse to run. But if you set DYLD_FALLBACK_LIBRARY_PATH, you can have your custom libraries and X11 at the same time. Great answer!

    CommentedDec 4, 2011 at 3:58 

  • 6
    Something seems fishy here: According to the docs, the default library search path is used if DYLD_FALLBACK_LIBRARY_PATH is not set. Setting it will cause the default paths to be ignored, causing lots of problems. (At least this is what I find happening with Mountain Lion.) If you modify DYLD_FALLBACK_LIBRARY_PATH, then it seems you must be careful to add the defaults manually. (See man dlopen.) Am I missing something?

    – mforbes

    CommentedMar 13, 2013 at 18:03

  • 3
    The Homebrew folks don’t appreciate DYLD_FALLBACK_LIBRARY_PATHgithub.com/mxcl/homebrew/issues/13463

    CommentedJun 13, 2013 at 17:18

  • 9
    DYLD_FALLBACK_LIBRARY_PATH seems to be unusable in El Capitan cause to security reasons. Any ideas?

    – Lupurus

    CommentedOct 5, 2015 at 7:12

  • when installing cuda we are told to set export DYLD_LIBRARY_PATH=/Developer/NVIDIA/CUDA-7.0/lib:$DYLD_LIBRARY_PATH

    CommentedApr 15, 2016 at 19:59 

Leave a Reply

The maximum upload file size: 500 MB. You can upload: image, audio, video, document, spreadsheet, interactive, other. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here