DYLD_FALLBACK_LIBRARY_PATH (OS X)

Maybe everyone knew this already, but it took ages to work out what was wrong, so...

Upgrading to Tiger caused problems with launching applications from the Terminal: commands like 'open', by opening files in Preview, would try to use Apple's image libraries (libJPG.dylib, libTIFF.dyib, libPng.dylib, etc) which are part of the ImageIO framework, but wouldn't be able to get to them because I had libraries of the same name in /usr/local/lib.

The path for dynamic libraries was defined by the DYLD_LIBRARY_PATH environment variable, so applications were looking there first. I couldn't add Apple's libraries to the path first, as they were missing symbols that were in the official libraries, and I couldn't just upgrade the official libraries as Apple's versions had extra symbols that weren't present in the originals. On most Unix systems it wouldn't be a problem as the filenames are actually different, but OS X is case-insensitive so that didn't help either.

In the end the solution was to use DYLD_FALLBACK_LIBRARY_PATH instead of DYLD_LIBRARY_PATH: this made dyld look in Apple's libraries first, then in /usr/local/lib if it couldn't find what it needed there. There were a few conflicts with older versions of libraries in /usr/X11R6/lib, but those could be safely moved out of the way. I had to add /usr/local/lib to LD_LIBRARY_PATH as well, because some programs were looking for libraries there.