0
votes

I'm trying to understand the process by which Mac OS Catalina determines the locations of dynamic libraries and resolves name conflicts at runtime. The information on this website:

https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryUsageGuidelines.html#//apple_ref/doc/uid/TP40001928-SW12

implies that there is a search hierarchy that starts with the contents of LD_LIBRARY_PATH and moves through a number of other environment variables; that one of these, DYLD_FALLBACK_LIBRARY_PATH, has default values if not explicitly set that include locations like /usr/lib .

Then I see that if I look at a library's dependencies with ldd -d, it shows the dependencies for each library with path information:

nasmac3465:libs ptenenba$ ldd -d libtess-mod.dylib
libtess-mod.dylib:
Contents of (__DATA,__data) section
000000000001cb80    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
000000000001cb90    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
000000000001cba0    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    /Users/ptenenba/git/tess/spoc/code/dist/libs/libtess-mod.dylib (compatibility version 0.0.0, current version 0.0.0)
    /opt/local/lib/libgcc/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.28.0)
    /Users/ptenenba/git/tess/spoc/code/dist/libs/libtess-common.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)
    /opt/local/lib/libgcc/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
nasmac3465:libs ptenenba$ 

My question: why do I need to specify any library search paths using LD_LIBRARY_PATH or DYLD_LIBRARY_PATH when each library has both the name and the path of its dependencies?

1

1 Answers

0
votes

Normally it is unnecessary and undesirable to use the environment variables with dyld the dynamic library loader. The paths should instead be set during the link phase, or modified later with install_name_tool.