• Static Linking: at compile time
  • Dynamic Linking: at runtime, operating system looks for .so (linux) .dll (win) .dylib (mac) extensions

Dynamic Linking

Where Are They?

OS looks for dynamic libraries in:

  • Mac
    1. Paths baked into the binary (via @rpath, @executable_path, @loader_path)
    2. DYLD_LIBRARY_PATH (if not restricted by SIP).
    3. Default system locations:
      • /usr/lib/
      • /usr/local/lib/
  • Linux
    1. RPATH, RUNPATH in the binary (ldd shows them).
    2. LD_LIBRARY_PATH environment variable.
    3. Configured dirs in /etc/ld.so.conf and /etc/ld.so.conf.d/.
    4. Standard locations:
      • /lib
      • /usr/lib
      • /usr/local/lib
  • Windows
    1. The directory containing the executable.
    2. System directories (C:\Windows\System32, C:\Windows\SysWOW64).
    3. Current working directory.
    4. Directories in the PATH environment variable.

At Runtime

Dynamic Linker (ld.so (linux), dyld on mac, Windows loader on win)matches all undefined symbols in the symbol table in the program with exported symbols by the dynamic libraries