- 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
- Paths baked into the binary (via @rpath, @executable_path, @loader_path)
DYLD_LIBRARY_PATH(if not restricted by SIP).- Default system locations:
- /usr/lib/
- /usr/local/lib/
- Linux
RPATH,RUNPATHin the binary (lddshows them).LD_LIBRARY_PATHenvironment variable.- Configured dirs in /etc/ld.so.conf and /etc/ld.so.conf.d/.
- Standard locations:
- /lib
- /usr/lib
- /usr/local/lib
- Windows
- The directory containing the executable.
- System directories (
C:\Windows\System32,C:\Windows\SysWOW64). - Current working directory.
- Directories in the
PATHenvironment 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