I read some articles discouraging of the use of DYLD_LIBRARY_PATH, as the the path of dynamic library should be fixed using -install_name, @rpath, and @loader_path.
In terms of making a program that runs both on Linux and Mac OS X, DYLD_LIBRARY_PATH of Mac OS X does exactly what LD_LIBRARY_PATH of Linux. And, we can share (almost) the same make file that doesn't have the -install_name and @rpath.
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.